diff --git a/Makefile b/Makefile index 7ac27c4f03..fdfaae15c5 100755 --- a/Makefile +++ b/Makefile @@ -19,15 +19,17 @@ integ-test: black: black setup.py samtranslator/* tests/* integration/* bin/*.py + bin/json-format.py --write tests black-check: black --check setup.py samtranslator/* tests/* integration/* bin/*.py + bin/json-format.py --check tests lint: # Linter performs static analysis to catch latent bugs pylint --rcfile .pylintrc samtranslator # mypy performs type check - mypy samtranslator bin/add_transform_test.py + mypy samtranslator bin/add_transform_test.py bin/json-format.py prepare-companion-stack: pytest -v --no-cov integration/setup -m setup diff --git a/bin/json-format.py b/bin/json-format.py new file mode 100755 index 0000000000..2218c947c3 --- /dev/null +++ b/bin/json-format.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python +"""JSON file formatter (without prettier).""" +import argparse +import json +import os.path +import sys + + +def format_json(json_str: str) -> str: + """Opinionated format JSON file.""" + obj = json.loads(json_str) + return json.dumps(obj, indent=2, sort_keys=True) + "\n" + + +class JSONFormatter: + check: bool + write: bool + + scanned_file_found: int + unformatted_file_count: int + + def __init__(self, check: bool, write: bool) -> None: + self.check = check + self.write = write + + self.scanned_file_found = 0 + self.unformatted_file_count = 0 + + def process_file(self, file_path: str) -> None: + with open(file_path, "r", encoding="utf-8") as f: + json_str = f.read() + try: + formatted_json_str = format_json(json_str) + except json.JSONDecodeError as error: + raise ValueError(f"{file_path}: Invalid JSON") from error + if json_str != formatted_json_str: + if self.write: + with open(file_path, "w", encoding="utf-8") as f: + f.write(formatted_json_str) + print(f"reformatted {file_path}") + if self.check: + print(f"would reformat {file_path}") + self.unformatted_file_count += 1 + self.scanned_file_found += 1 + + def process_directory(self, directory_path: str) -> None: + for root, dirs, files in os.walk(directory_path): + for file in files: + file_path = os.path.join(root, file) + _, extension = os.path.splitext(file_path) + if extension != ".json": + continue + self.process_file(file_path) + + def output_summary(self): + print(f"{self.scanned_file_found} file(s) scanned.") + if self.write: + print(f"{self.unformatted_file_count} file(s) reformatted.") + if self.check: + print(f"{self.unformatted_file_count} file(s) need reformat.") + if self.unformatted_file_count: + sys.exit(-1) + + +def main() -> None: + parser = argparse.ArgumentParser(description="JSON file formatter.") + parser.add_argument( + "paths", metavar="file|dir", type=str, nargs="+", help="JSON file or directory containing JSON files" + ) + group = parser.add_mutually_exclusive_group() + group.add_argument( + "-c", + "--check", + action="store_true", + help="Check if the given files are formatted, " + "print a human-friendly summary message and paths to un-formatted files", + ) + group.add_argument( + "-w", + "--write", + action="store_true", + help="Edit files in-place. (Beware!)", + ) + + args = parser.parse_args() + formatter = JSONFormatter(args.check, args.write) + + for path in args.paths: + if not os.path.exists(path): + raise ValueError(f"{path}: No such file or directory") + if os.path.isfile(path): + _, extension = os.path.splitext(path) + if extension != ".json": + raise ValueError(f"{path}: Not a JSON file") + formatter.process_file(path) + elif os.path.isdir(path): + formatter.process_directory(path) + else: + raise ValueError(f"{path}: Unsupported path") + + formatter.output_summary() + + +if __name__ == "__main__": + main() diff --git a/tests/feature_toggle/input/feature_toggle_config.json b/tests/feature_toggle/input/feature_toggle_config.json index 710f42cff1..d2d82ca3d4 100644 --- a/tests/feature_toggle/input/feature_toggle_config.json +++ b/tests/feature_toggle/input/feature_toggle_config.json @@ -1,22 +1,50 @@ { - "__note__": "This is a dummy config for local testing. Any change here need to be migrated to SAM service.", - "feature-1": { - "beta": { - "us-west-2": {"type": "toggle", "enabled": true}, - "us-east-1": {"type": "account-percentile", "enabled-%": 10}, - "default": {"type": "toggle", "enabled": false}, - "123456789123": { - "us-west-2": {"type": "toggle", "enabled": true}, - "default": {"type": "toggle", "enabled": false} - } + "__note__": "This is a dummy config for local testing. Any change here need to be migrated to SAM service.", + "feature-1": { + "beta": { + "123456789123": { + "default": { + "enabled": false, + "type": "toggle" }, - "gamma": { - "default": {"type": "toggle", "enabled": false}, - "123456789123": { - "us-east-1": {"type": "toggle", "enabled": false}, - "default": {"type": "toggle", "enabled": false} - } + "us-west-2": { + "enabled": true, + "type": "toggle" + } + }, + "default": { + "enabled": false, + "type": "toggle" + }, + "us-east-1": { + "enabled-%": 10, + "type": "account-percentile" + }, + "us-west-2": { + "enabled": true, + "type": "toggle" + } + }, + "gamma": { + "123456789123": { + "default": { + "enabled": false, + "type": "toggle" }, - "prod": {"default": {"enabled": false}} + "us-east-1": { + "enabled": false, + "type": "toggle" + } + }, + "default": { + "enabled": false, + "type": "toggle" + } + }, + "prod": { + "default": { + "enabled": false + } } + } } diff --git a/tests/translator/output/alexa_skill.json b/tests/translator/output/alexa_skill.json index bb86ba2bea..768493479a 100644 --- a/tests/translator/output/alexa_skill.json +++ b/tests/translator/output/alexa_skill.json @@ -1,72 +1,72 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", + "AlexaSkillFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/alexa_skill_with_skill_id.json b/tests/translator/output/alexa_skill_with_skill_id.json index a02b881ab1..7039d07690 100644 --- a/tests/translator/output/alexa_skill_with_skill_id.json +++ b/tests/translator/output/alexa_skill_with_skill_id.json @@ -1,73 +1,73 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, - "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, + "Resources": { + "AlexaSkillFunc": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "EventSourceToken": "amzn1.ask.skill.12345678-1234-1234-1234-123456789", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com", - "EventSourceToken": "amzn1.ask.skill.12345678-1234-1234-1234-123456789" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Tags": [ + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } +} diff --git a/tests/translator/output/all_policy_templates.json b/tests/translator/output/all_policy_templates.json index a751bff434..5552177c5a 100644 --- a/tests/translator/output/all_policy_templates.json +++ b/tests/translator/output/all_policy_templates.json @@ -1,1500 +1,1498 @@ { "Resources": { "KitchenSinkFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "KitchenSinkFunctionRole", + "KitchenSinkFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "KitchenSinkFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "KitchenSinkFunctionRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "sqs:ChangeMessageVisibility", - "sqs:ChangeMessageVisibilityBatch", - "sqs:DeleteMessage", - "sqs:DeleteMessageBatch", - "sqs:GetQueueAttributes", + "sqs:ChangeMessageVisibility", + "sqs:ChangeMessageVisibilityBatch", + "sqs:DeleteMessage", + "sqs:DeleteMessageBatch", + "sqs:GetQueueAttributes", "sqs:ReceiveMessage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy0" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { "functionName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy1" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ "cloudwatch:DescribeAlarmHistory" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy2" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy3", "PolicyDocument": { "Statement": [ { "Action": [ "cloudwatch:PutMetricData" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy3" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy4", "PolicyDocument": { "Statement": [ { "Action": [ - "ec2:DescribeRegions", + "ec2:DescribeRegions", "ec2:DescribeInstances" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy4" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy5", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:GetItem", - "dynamodb:DeleteItem", - "dynamodb:PutItem", - "dynamodb:Scan", - "dynamodb:Query", - "dynamodb:UpdateItem", - "dynamodb:BatchWriteItem", - "dynamodb:BatchGetItem", - "dynamodb:DescribeTable", + "dynamodb:GetItem", + "dynamodb:DeleteItem", + "dynamodb:PutItem", + "dynamodb:Scan", + "dynamodb:Query", + "dynamodb:UpdateItem", + "dynamodb:BatchWriteItem", + "dynamodb:BatchGetItem", + "dynamodb:DescribeTable", "dynamodb:ConditionCheckItem" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", { "tableName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy5" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy6", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:GetItem", - "dynamodb:Scan", - "dynamodb:Query", - "dynamodb:BatchGetItem", + "dynamodb:GetItem", + "dynamodb:Scan", + "dynamodb:Query", + "dynamodb:BatchGetItem", "dynamodb:DescribeTable" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", { "tableName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy6" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy7", "PolicyDocument": { "Statement": [ { "Action": [ "ses:SendBounce" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy7" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy8", "PolicyDocument": { "Statement": [ { "Action": [ - "es:ESHttpPost", + "es:ESHttpPost", "es:ESHttpPut" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain/${domainName}/*", + "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain/${domainName}/*", { "domainName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy8" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy9", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetObjectVersion", + "s3:GetObject", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetObjectVersion", "s3:GetLifecycleConfiguration" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy9" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy10", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:GetLifecycleConfiguration", - "s3:PutLifecycleConfiguration", + "s3:GetObject", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetLifecycleConfiguration", + "s3:PutLifecycleConfiguration", "s3:DeleteObject" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy10" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy11", "PolicyDocument": { "Statement": [ { "Action": [ "ec2:DescribeImages" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy11" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy12", "PolicyDocument": { "Statement": [ { "Action": [ "cloudformation:DescribeStacks" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/*" - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy12" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy13", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CompareFaces", - "rekognition:DetectFaces", - "rekognition:DetectLabels", + "rekognition:CompareFaces", + "rekognition:DetectFaces", + "rekognition:DetectLabels", "rekognition:DetectModerationLabels" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy13" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy14", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:ListCollections", - "rekognition:ListFaces", - "rekognition:SearchFaces", + "rekognition:ListCollections", + "rekognition:ListFaces", + "rekognition:SearchFaces", "rekognition:SearchFacesByImage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy14" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy15", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CreateCollection", + "rekognition:CreateCollection", "rekognition:IndexFaces" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy15" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy16", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy16" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy17", "PolicyDocument": { "Statement": [ { "Action": [ "sns:Publish" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}", + "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}", { "topicName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy17" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy18", "PolicyDocument": { "Statement": [ { "Action": [ - "ec2:CreateNetworkInterface", - "ec2:DeleteNetworkInterface", - "ec2:DescribeNetworkInterfaces", + "ec2:CreateNetworkInterface", + "ec2:DeleteNetworkInterface", + "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy18" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy19", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:DescribeStream", - "dynamodb:GetRecords", + "dynamodb:DescribeStream", + "dynamodb:GetRecords", "dynamodb:GetShardIterator" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/${streamName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/${streamName}", { - "streamName": "name", + "streamName": "name", "tableName": "name" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ "dynamodb:ListStreams" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/*", { "tableName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy19" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy20", "PolicyDocument": { "Statement": [ { "Action": [ - "kinesis:ListStreams", + "kinesis:ListStreams", "kinesis:DescribeLimits" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/*" - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "kinesis:DescribeStream", - "kinesis:DescribeStreamSummary", - "kinesis:GetRecords", + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetRecords", "kinesis:GetShardIterator" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", + "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", { "streamName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy20" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy21", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:GetIdentityVerificationAttributes", - "ses:SendEmail", - "ses:SendRawEmail", + "ses:GetIdentityVerificationAttributes", + "ses:SendEmail", + "ses:SendRawEmail", "ses:VerifyEmailIdentity" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy21" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy22", "PolicyDocument": { "Statement": [ { "Action": [ - "sns:ListSubscriptionsByTopic", - "sns:CreateTopic", - "sns:SetTopicAttributes", - "sns:Subscribe", + "sns:ListSubscriptionsByTopic", + "sns:CreateTopic", + "sns:SetTopicAttributes", + "sns:Subscribe", "sns:Publish" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}*", + "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}*", { "topicName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy22" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy23", "PolicyDocument": { "Statement": [ { "Action": [ - "kinesis:AddTagsToStream", - "kinesis:CreateStream", - "kinesis:DecreaseStreamRetentionPeriod", - "kinesis:DeleteStream", - "kinesis:DescribeStream", - "kinesis:DescribeStreamSummary", - "kinesis:GetShardIterator", - "kinesis:IncreaseStreamRetentionPeriod", - "kinesis:ListTagsForStream", - "kinesis:MergeShards", - "kinesis:PutRecord", - "kinesis:PutRecords", - "kinesis:SplitShard", + "kinesis:AddTagsToStream", + "kinesis:CreateStream", + "kinesis:DecreaseStreamRetentionPeriod", + "kinesis:DeleteStream", + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetShardIterator", + "kinesis:IncreaseStreamRetentionPeriod", + "kinesis:ListTagsForStream", + "kinesis:MergeShards", + "kinesis:PutRecord", + "kinesis:PutRecords", + "kinesis:SplitShard", "kinesis:RemoveTagsFromStream" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", + "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", { "streamName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy23" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy24", "PolicyDocument": { "Statement": [ { - "Action": "kms:Decrypt", + "Action": "kms:Decrypt", + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", + "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", { "keyId": "keyId" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy24" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy25", "PolicyDocument": { "Statement": [ { "Action": [ - "polly:GetLexicon", + "polly:GetLexicon", "polly:DeleteLexicon" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/${lexiconName}", + "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/${lexiconName}", { "lexiconName": "name" } ] } - ], - "Effect": "Allow" - }, + ] + }, { "Action": [ - "polly:DescribeVoices", - "polly:ListLexicons", - "polly:PutLexicon", + "polly:DescribeVoices", + "polly:ListLexicons", + "polly:PutLexicon", "polly:SynthesizeSpeech" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/*" } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy25" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy26", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:GetObjectAcl", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:DeleteObject", - "s3:DeleteObjectTagging", - "s3:DeleteObjectVersionTagging", - "s3:GetObjectTagging", - "s3:GetObjectVersionTagging", - "s3:PutObjectTagging", + "s3:GetObject", + "s3:GetObjectAcl", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:DeleteObject", + "s3:DeleteObjectTagging", + "s3:DeleteObjectVersionTagging", + "s3:GetObjectTagging", + "s3:GetObjectVersionTagging", + "s3:PutObjectTagging", "s3:PutObjectVersionTagging" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" - }, + ] + }, { "Action": [ - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetLifecycleConfiguration", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetLifecycleConfiguration", "s3:PutLifecycleConfiguration" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy26" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy27", "PolicyDocument": { "Statement": [ { "Action": [ - "codepipeline:PutJobSuccessResult", + "codepipeline:PutJobSuccessResult", "codepipeline:PutJobFailureResult" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy27" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy28", "PolicyDocument": { "Statement": [ { "Action": [ - "serverlessrepo:CreateApplication", - "serverlessrepo:CreateApplicationVersion", - "serverlessrepo:UpdateApplication", - "serverlessrepo:GetApplication", - "serverlessrepo:ListApplications", - "serverlessrepo:ListApplicationVersions", + "serverlessrepo:CreateApplication", + "serverlessrepo:CreateApplicationVersion", + "serverlessrepo:UpdateApplication", + "serverlessrepo:GetApplication", + "serverlessrepo:ListApplications", + "serverlessrepo:ListApplicationVersions", "serverlessrepo:ListApplicationDependencies" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:serverlessrepo:${AWS::Region}:${AWS::AccountId}:applications/*" } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy28" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy29", "PolicyDocument": { "Statement": [ { "Action": [ "ec2:CopyImage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:image/${imageId}", + "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:image/${imageId}", { "imageId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy29" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy30", "PolicyDocument": { "Statement": [ { "Action": [ "codepipeline:ListPipelineExecutions" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipelinename}", + "arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipelinename}", { "pipelinename": "pipeline" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy30" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy31", "PolicyDocument": { "Statement": [ { "Action": [ - "cloudwatch:GetDashboard", - "cloudwatch:ListDashboards", - "cloudwatch:PutDashboard", + "cloudwatch:GetDashboard", + "cloudwatch:ListDashboards", + "cloudwatch:PutDashboard", "cloudwatch:ListMetrics" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy31" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy32", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CompareFaces", + "rekognition:CompareFaces", "rekognition:DetectFaces" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy32" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy33", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:DetectLabels", + "rekognition:DetectLabels", "rekognition:DetectModerationLabels" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy33" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy34", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:CreateBackup", + "dynamodb:CreateBackup", "dynamodb:DescribeContinuousBackups" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "table" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "dynamodb:DeleteBackup", - "dynamodb:DescribeBackup", + "dynamodb:DeleteBackup", + "dynamodb:DescribeBackup", "dynamodb:ListBackups" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", { "tableName": "table" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy34" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy35", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:RestoreTableFromBackup" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", { "tableName": "table" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "dynamodb:PutItem", - "dynamodb:UpdateItem", - "dynamodb:DeleteItem", - "dynamodb:GetItem", - "dynamodb:Query", - "dynamodb:Scan", + "dynamodb:PutItem", + "dynamodb:UpdateItem", + "dynamodb:DeleteItem", + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", "dynamodb:BatchWriteItem" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "table" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy35" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy36", "PolicyDocument": { "Statement": [ { "Action": [ - "comprehend:BatchDetectKeyPhrases", - "comprehend:DetectDominantLanguage", - "comprehend:DetectEntities", - "comprehend:BatchDetectEntities", - "comprehend:DetectKeyPhrases", - "comprehend:DetectSentiment", - "comprehend:BatchDetectDominantLanguage", + "comprehend:BatchDetectKeyPhrases", + "comprehend:DetectDominantLanguage", + "comprehend:DetectEntities", + "comprehend:BatchDetectEntities", + "comprehend:DetectKeyPhrases", + "comprehend:DetectSentiment", + "comprehend:BatchDetectDominantLanguage", "comprehend:BatchDetectSentiment" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy36" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy37", "PolicyDocument": { "Statement": [ { "Action": [ - "secretsmanager:DescribeSecret", - "secretsmanager:GetSecretValue", - "secretsmanager:PutSecretValue", + "secretsmanager:DescribeSecret", + "secretsmanager:GetSecretValue", + "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" - ], - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" - }, - "Effect": "Allow", + ], "Condition": { "StringEquals": { "secretsmanager:resource/AllowRotationLambdaArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}", { "functionName": "function" } ] } } + }, + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" } - }, + }, { "Action": [ "secretsmanager:GetRandomPassword" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy37" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy38", "PolicyDocument": { "Statement": [ { "Action": [ "mobileanalytics:PutEvents" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy38" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy39", "PolicyDocument": { "Statement": [ { "Action": [ - "mobiletargeting:GetEndpoint", - "mobiletargeting:UpdateEndpoint", + "mobiletargeting:GetEndpoint", + "mobiletargeting:UpdateEndpoint", "mobiletargeting:UpdateEndpointsBatch" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${pinpointApplicationId}/endpoints/*", + "arn:${AWS::Partition}:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${pinpointApplicationId}/endpoints/*", { "pinpointApplicationId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy39" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy40", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:DetectFaces", - "rekognition:DetectLabels", - "rekognition:DetectModerationLabels", + "rekognition:DetectFaces", + "rekognition:DetectLabels", + "rekognition:DetectModerationLabels", "rekognition:DetectText" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy40" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy41", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:IndexFaces", - "rekognition:DeleteFaces", - "rekognition:SearchFaces", - "rekognition:SearchFacesByImage", + "rekognition:IndexFaces", + "rekognition:DeleteFaces", + "rekognition:SearchFaces", + "rekognition:SearchFacesByImage", "rekognition:ListFaces" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "collection" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy41" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy42", "PolicyDocument": { "Statement": [ { "Action": [ - "eks:DescribeCluster", + "eks:DescribeCluster", "eks:ListClusters" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy42" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy43", "PolicyDocument": { "Statement": [ { "Action": [ - "ce:GetCostAndUsage", - "ce:GetDimensionValues", - "ce:GetReservationCoverage", - "ce:GetReservationPurchaseRecommendation", - "ce:GetReservationUtilization", + "ce:GetCostAndUsage", + "ce:GetDimensionValues", + "ce:GetReservationCoverage", + "ce:GetReservationPurchaseRecommendation", + "ce:GetReservationUtilization", "ce:GetTags" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy43" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy44", "PolicyDocument": { "Statement": [ { "Action": [ "organizations:ListAccounts" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy44" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy45", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:UpdateTable" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy45" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy46", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:GetIdentityVerificationAttributes", - "ses:SendEmail", - "ses:SendRawEmail", - "ses:SendTemplatedEmail", - "ses:SendBulkTemplatedEmail", + "ses:GetIdentityVerificationAttributes", + "ses:SendEmail", + "ses:SendRawEmail", + "ses:SendTemplatedEmail", + "ses:SendBulkTemplatedEmail", "ses:VerifyEmailIdentity" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy46" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy47", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:CreateTemplate", - "ses:GetTemplate", - "ses:ListTemplates", - "ses:UpdateTemplate", - "ses:DeleteTemplate", + "ses:CreateTemplate", + "ses:GetTemplate", + "ses:ListTemplates", + "ses:UpdateTemplate", + "ses:DeleteTemplate", "ses:TestRenderTemplate" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy47" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy48", "PolicyDocument": { "Statement": [ { "Action": [ "logs:FilterLogEvents" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${logGroupName}:log-stream:*", + "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${logGroupName}:log-stream:*", { "logGroupName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy48" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy49", "PolicyDocument": { "Statement": [ { "Action": [ "ssm:DescribeParameters" - ], - "Resource": "*", - "Effect": "Allow" - }, + ], + "Effect": "Allow", + "Resource": "*" + }, { "Action": [ - "ssm:GetParameters", - "ssm:GetParameter", + "ssm:GetParameters", + "ssm:GetParameter", "ssm:GetParametersByPath" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${parameterName}", + "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${parameterName}", { "parameterName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy49" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy50", "PolicyDocument": { "Statement": [ { "Action": [ "states:StartExecution" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy50" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy51", "PolicyDocument": { "Statement": [ { "Action": [ - "codecommit:GitPull", - "codecommit:GitPush", - "codecommit:CreateBranch", - "codecommit:DeleteBranch", - "codecommit:GetBranch", - "codecommit:ListBranches", - "codecommit:MergeBranchesByFastForward", - "codecommit:MergeBranchesBySquash", - "codecommit:MergeBranchesByThreeWay", - "codecommit:UpdateDefaultBranch", - "codecommit:BatchDescribeMergeConflicts", - "codecommit:CreateUnreferencedMergeCommit", - "codecommit:DescribeMergeConflicts", - "codecommit:GetMergeCommit", - "codecommit:GetMergeOptions", - "codecommit:BatchGetPullRequests", - "codecommit:CreatePullRequest", - "codecommit:DescribePullRequestEvents", - "codecommit:GetCommentsForPullRequest", - "codecommit:GetCommitsFromMergeBase", - "codecommit:GetMergeConflicts", - "codecommit:GetPullRequest", - "codecommit:ListPullRequests", - "codecommit:MergePullRequestByFastForward", - "codecommit:MergePullRequestBySquash", - "codecommit:MergePullRequestByThreeWay", - "codecommit:PostCommentForPullRequest", - "codecommit:UpdatePullRequestDescription", - "codecommit:UpdatePullRequestStatus", - "codecommit:UpdatePullRequestTitle", - "codecommit:DeleteFile", - "codecommit:GetBlob", - "codecommit:GetFile", - "codecommit:GetFolder", - "codecommit:PutFile", - "codecommit:DeleteCommentContent", - "codecommit:GetComment", - "codecommit:GetCommentsForComparedCommit", - "codecommit:PostCommentForComparedCommit", - "codecommit:PostCommentReply", - "codecommit:UpdateComment", - "codecommit:BatchGetCommits", - "codecommit:CreateCommit", - "codecommit:GetCommit", - "codecommit:GetCommitHistory", - "codecommit:GetDifferences", - "codecommit:GetObjectIdentifier", - "codecommit:GetReferences", - "codecommit:GetTree", - "codecommit:GetRepository", - "codecommit:UpdateRepositoryDescription", - "codecommit:ListTagsForResource", - "codecommit:TagResource", - "codecommit:UntagResource", - "codecommit:GetRepositoryTriggers", - "codecommit:PutRepositoryTriggers", - "codecommit:TestRepositoryTriggers", - "codecommit:GetBranch", - "codecommit:GetCommit", - "codecommit:UploadArchive", - "codecommit:GetUploadArchiveStatus", + "codecommit:GitPull", + "codecommit:GitPush", + "codecommit:CreateBranch", + "codecommit:DeleteBranch", + "codecommit:GetBranch", + "codecommit:ListBranches", + "codecommit:MergeBranchesByFastForward", + "codecommit:MergeBranchesBySquash", + "codecommit:MergeBranchesByThreeWay", + "codecommit:UpdateDefaultBranch", + "codecommit:BatchDescribeMergeConflicts", + "codecommit:CreateUnreferencedMergeCommit", + "codecommit:DescribeMergeConflicts", + "codecommit:GetMergeCommit", + "codecommit:GetMergeOptions", + "codecommit:BatchGetPullRequests", + "codecommit:CreatePullRequest", + "codecommit:DescribePullRequestEvents", + "codecommit:GetCommentsForPullRequest", + "codecommit:GetCommitsFromMergeBase", + "codecommit:GetMergeConflicts", + "codecommit:GetPullRequest", + "codecommit:ListPullRequests", + "codecommit:MergePullRequestByFastForward", + "codecommit:MergePullRequestBySquash", + "codecommit:MergePullRequestByThreeWay", + "codecommit:PostCommentForPullRequest", + "codecommit:UpdatePullRequestDescription", + "codecommit:UpdatePullRequestStatus", + "codecommit:UpdatePullRequestTitle", + "codecommit:DeleteFile", + "codecommit:GetBlob", + "codecommit:GetFile", + "codecommit:GetFolder", + "codecommit:PutFile", + "codecommit:DeleteCommentContent", + "codecommit:GetComment", + "codecommit:GetCommentsForComparedCommit", + "codecommit:PostCommentForComparedCommit", + "codecommit:PostCommentReply", + "codecommit:UpdateComment", + "codecommit:BatchGetCommits", + "codecommit:CreateCommit", + "codecommit:GetCommit", + "codecommit:GetCommitHistory", + "codecommit:GetDifferences", + "codecommit:GetObjectIdentifier", + "codecommit:GetReferences", + "codecommit:GetTree", + "codecommit:GetRepository", + "codecommit:UpdateRepositoryDescription", + "codecommit:ListTagsForResource", + "codecommit:TagResource", + "codecommit:UntagResource", + "codecommit:GetRepositoryTriggers", + "codecommit:PutRepositoryTriggers", + "codecommit:TestRepositoryTriggers", + "codecommit:GetBranch", + "codecommit:GetCommit", + "codecommit:UploadArchive", + "codecommit:GetUploadArchiveStatus", "codecommit:CancelUploadArchive" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", + "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", { "repositoryName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy51" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy52", "PolicyDocument": { "Statement": [ { "Action": [ - "codecommit:GitPull", - "codecommit:GetBranch", - "codecommit:ListBranches", - "codecommit:BatchDescribeMergeConflicts", - "codecommit:DescribeMergeConflicts", - "codecommit:GetMergeCommit", - "codecommit:GetMergeOptions", - "codecommit:BatchGetPullRequests", - "codecommit:DescribePullRequestEvents", - "codecommit:GetCommentsForPullRequest", - "codecommit:GetCommitsFromMergeBase", - "codecommit:GetMergeConflicts", - "codecommit:GetPullRequest", - "codecommit:ListPullRequests", - "codecommit:GetBlob", - "codecommit:GetFile", - "codecommit:GetFolder", - "codecommit:GetComment", - "codecommit:GetCommentsForComparedCommit", - "codecommit:BatchGetCommits", - "codecommit:GetCommit", - "codecommit:GetCommitHistory", - "codecommit:GetDifferences", - "codecommit:GetObjectIdentifier", - "codecommit:GetReferences", - "codecommit:GetTree", - "codecommit:GetRepository", - "codecommit:ListTagsForResource", - "codecommit:GetRepositoryTriggers", - "codecommit:TestRepositoryTriggers", - "codecommit:GetBranch", - "codecommit:GetCommit", + "codecommit:GitPull", + "codecommit:GetBranch", + "codecommit:ListBranches", + "codecommit:BatchDescribeMergeConflicts", + "codecommit:DescribeMergeConflicts", + "codecommit:GetMergeCommit", + "codecommit:GetMergeOptions", + "codecommit:BatchGetPullRequests", + "codecommit:DescribePullRequestEvents", + "codecommit:GetCommentsForPullRequest", + "codecommit:GetCommitsFromMergeBase", + "codecommit:GetMergeConflicts", + "codecommit:GetPullRequest", + "codecommit:ListPullRequests", + "codecommit:GetBlob", + "codecommit:GetFile", + "codecommit:GetFolder", + "codecommit:GetComment", + "codecommit:GetCommentsForComparedCommit", + "codecommit:BatchGetCommits", + "codecommit:GetCommit", + "codecommit:GetCommitHistory", + "codecommit:GetDifferences", + "codecommit:GetObjectIdentifier", + "codecommit:GetReferences", + "codecommit:GetTree", + "codecommit:GetRepository", + "codecommit:ListTagsForResource", + "codecommit:GetRepositoryTriggers", + "codecommit:TestRepositoryTriggers", + "codecommit:GetBranch", + "codecommit:GetCommit", "codecommit:GetUploadArchiveStatus" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", + "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", { "repositoryName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy52" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy53", "PolicyDocument": { "Statement": [ { - "Action": "kms:Encrypt", + "Action": "kms:Encrypt", + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", + "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", { "keyId": "keyId" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy53" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy54", "PolicyDocument": { "Statement": [ { "Action": [ - "athena:ListWorkGroups", - "athena:GetExecutionEngine", - "athena:GetExecutionEngines", - "athena:GetNamespace", - "athena:GetCatalogs", - "athena:GetNamespaces", - "athena:GetTables", + "athena:ListWorkGroups", + "athena:GetExecutionEngine", + "athena:GetExecutionEngines", + "athena:GetNamespace", + "athena:GetCatalogs", + "athena:GetNamespaces", + "athena:GetTables", "athena:GetTable" - ], - "Resource": "*", - "Effect": "Allow" - }, - { - "Action": [ - "athena:StartQueryExecution", - "athena:GetQueryResults", - "athena:DeleteNamedQuery", - "athena:GetNamedQuery", - "athena:ListQueryExecutions", - "athena:StopQueryExecution", - "athena:GetQueryResultsStream", - "athena:ListNamedQueries", - "athena:CreateNamedQuery", - "athena:GetQueryExecution", - "athena:BatchGetNamedQuery", - "athena:BatchGetQueryExecution", + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "athena:StartQueryExecution", + "athena:GetQueryResults", + "athena:DeleteNamedQuery", + "athena:GetNamedQuery", + "athena:ListQueryExecutions", + "athena:StopQueryExecution", + "athena:GetQueryResultsStream", + "athena:ListNamedQueries", + "athena:CreateNamedQuery", + "athena:GetQueryExecution", + "athena:BatchGetNamedQuery", + "athena:BatchGetQueryExecution", "athena:GetWorkGroup" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/${workgroupName}", + "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/${workgroupName}", { "workgroupName": "name" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy54" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy55", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:PutLifecycleConfiguration" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -1515,19 +1513,19 @@ ] } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy55" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy56", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "dynamodb:PutItem", "dynamodb:UpdateItem", "dynamodb:BatchWriteItem" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -1548,14 +1546,15 @@ ] } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy56" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy57", "PolicyDocument": { "Statement": [ { "Action": "events:PutEvents", + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBusName}", @@ -1563,20 +1562,20 @@ "eventBusName": "name" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy57" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy58", "PolicyDocument": { "Statement": [ { "Action": [ "acm:GetCertificate" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${certificateArn}", @@ -1584,20 +1583,20 @@ "certificateArn": "arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy58" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy59", "PolicyDocument": { "Statement": [ { "Action": [ "route53:ChangeResourceRecordSets" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:route53:::hostedzone/${HostedZoneId}", @@ -1605,20 +1604,21 @@ "HostedZoneId": "test" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy59" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_cache.json b/tests/translator/output/api_cache.json index 08bcea21a1..49bb518b21 100644 --- a/tests/translator/output/api_cache.json +++ b/tests/translator/output/api_cache.json @@ -1,109 +1,109 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { - "CacheClusterEnabled": true, + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", "DeploymentId": { "Ref": "HtmlApiDeploymentf117c932f7" - }, + }, "RestApiId": { "Ref": "HtmlApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6" - } - }, + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_description.json b/tests/translator/output/api_description.json index 31cf8ed035..6e464bb8c8 100644 --- a/tests/translator/output/api_description.json +++ b/tests/translator/output/api_description.json @@ -1,108 +1,108 @@ { "Resources": { - "FunctionRole": { - "Type": "AWS::IAM::Role", + "Api": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "Description": "my description" + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiDeploymentf117c932f7" - }, + }, "RestApiId": { "Ref": "Api" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "Api" + "__ApiId__": "Api", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "Api": { - "Type": "AWS::ApiGateway::RestApi", + "FunctionRole": { "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "my description" - } - }, - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_endpoint_configuration.json b/tests/translator/output/api_endpoint_configuration.json index d38432e032..57c0ba225d 100644 --- a/tests/translator/output/api_endpoint_configuration.json +++ b/tests/translator/output/api_endpoint_configuration.json @@ -5,14 +5,52 @@ } }, "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -22,145 +60,84 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment62b96c1a61" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment62b96c1a61": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "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": {} + } } } }, @@ -178,7 +155,30 @@ "Ref": "EndpointConfig" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment62b96c1a61": { + "Properties": { + "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62b96c1a61" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_endpoint_configuration_with_vpcendpoint.json b/tests/translator/output/api_endpoint_configuration_with_vpcendpoint.json index 5167617b9d..0909aeeeb4 100644 --- a/tests/translator/output/api_endpoint_configuration_with_vpcendpoint.json +++ b/tests/translator/output/api_endpoint_configuration_with_vpcendpoint.json @@ -1,21 +1,64 @@ { "Parameters": { - "VpcEndpointId": { + "EndpointConfigType": { "Type": "String" }, - "EndpointConfigType": { + "VpcEndpointId": { "Type": "String" } }, "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ], + "VpcEndpointIds": [ + { + "Ref": "VpcEndpointId" + } + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -25,17 +68,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -48,141 +111,55 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "VpcEndpointIds": [ - { - "Ref": "VpcEndpointId" - } - ], - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment62b96c1a61" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment62b96c1a61": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "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" }, "EndpointConfiguration": { - "VpcEndpointIds": [ + "Types": [ { - "Ref": "VpcEndpointId" + "Ref": "EndpointConfigType" } ], - "Types": [ + "VpcEndpointIds": [ { - "Ref": "EndpointConfigType" + "Ref": "VpcEndpointId" } ] }, @@ -191,7 +168,30 @@ "Ref": "EndpointConfigType" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment62b96c1a61": { + "Properties": { + "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62b96c1a61" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_http_paths_with_if_condition.json b/tests/translator/output/api_http_paths_with_if_condition.json index 80957af7ae..8e4cbc6d90 100644 --- a/tests/translator/output/api_http_paths_with_if_condition.json +++ b/tests/translator/output/api_http_paths_with_if_condition.json @@ -1,178 +1,178 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] }, - "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Description": "sam-app\nSample SAM Template for sam-app\n", + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } + } + }, + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + }, + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - } + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/api_http_paths_with_if_condition_no_value_else_case.json b/tests/translator/output/api_http_paths_with_if_condition_no_value_else_case.json index 8a8f28e180..98c5b2f010 100644 --- a/tests/translator/output/api_http_paths_with_if_condition_no_value_else_case.json +++ b/tests/translator/output/api_http_paths_with_if_condition_no_value_else_case.json @@ -1,166 +1,166 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] }, - "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Description": "sam-app\nSample SAM Template for sam-app\n", + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/api_http_paths_with_if_condition_no_value_then_case.json b/tests/translator/output/api_http_paths_with_if_condition_no_value_then_case.json index efaa805a38..60a51eca54 100644 --- a/tests/translator/output/api_http_paths_with_if_condition_no_value_then_case.json +++ b/tests/translator/output/api_http_paths_with_if_condition_no_value_then_case.json @@ -1,66 +1,115 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", + "MyApi": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" + } } } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "Ref": "AWS::NoValue" + }, + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + } + }, + "Type": "AWS::ApiGatewayV2::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -80,87 +129,38 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + "MyAuthFnRole": { "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "Ref": "AWS::NoValue" - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ + "AssumeRolePolicyDocument": { + "Statement": [ { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_request_model.json b/tests/translator/output/api_request_model.json index f90ea14b49..7ce0f386e9 100644 --- a/tests/translator/output/api_request_model.json +++ b/tests/translator/output/api_request_model.json @@ -1,167 +1,98 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentcb065c609e" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlFunctionAnyPathPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", - { - "__ApiId__": "HtmlApi", - "__Stage__": "*" - } - ] - } - } - }, - "HtmlApiDeploymentcb065c609e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: cb065c609e3452b9ac6cc88cd778dce0647a0a10", - "StageName": "Stage" - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, "in": "body", "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "responses": {}, + } + } + }, + "/any": { + "x-amazon-apigateway-any-method": { "parameters": [ { "in": "body", "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" - }, - "required": true + } + } + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" } } } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentcb065c609e": { + "Properties": { + "Description": "RestApi deployment id: cb065c609e3452b9ac6cc88cd778dce0647a0a10", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentcb065c609e" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -177,11 +108,80 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionAnyPathPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_request_model_openapi_3.json b/tests/translator/output/api_request_model_openapi_3.json index a753e620a4..497ec66d52 100644 --- a/tests/translator/output/api_request_model_openapi_3.json +++ b/tests/translator/output/api_request_model_openapi_3.json @@ -1,101 +1,37 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "components": { + "schemas": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" } - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment8abd7f79f8" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionIamPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "HtmlApi" + }, + "securitySchemes": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" } } - ] - } - } - }, - "HtmlFunctionAnyIamPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", - { - "__ApiId__": { - "Ref": "HtmlApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { - "/iam": { + "/": { "get": { "requestBody": { "content": { @@ -104,27 +40,21 @@ "$ref": "#/components/schemas/user" } } - }, + }, "required": true - }, + }, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } - }, - "/": { - "get": { + }, + "/any/iam": { + "x-amazon-apigateway-any-method": { "requestBody": { "content": { "application/json": { @@ -132,28 +62,8 @@ "$ref": "#/components/schemas/user" } } - }, - "required": true - }, - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any/iam": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" }, - "credentials": "arn:aws:iam::*:user/*" + "required": true }, "responses": {}, "security": [ @@ -161,6 +71,18 @@ "AWS_IAM": [] } ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } + } + }, + "/iam": { + "get": { "requestBody": { "content": { "application/json": { @@ -170,84 +92,162 @@ } }, "required": true - } - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - }, - "schemas": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + }, + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } } } } } } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "HtmlApiDeployment8abd7f79f8": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 8abd7f79f8fd0aafe51e2201d63602c78a3e0e2a", + "RestApiId": { + "Ref": "HtmlApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment8abd7f79f8" + }, "RestApiId": { "Ref": "HtmlApi" }, - "Description": "RestApi deployment id: 8abd7f79f8fd0aafe51e2201d63602c78a3e0e2a" - } + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionAnyIamPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionIamPermissionProd": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_request_model_with_validator.json b/tests/translator/output/api_request_model_with_validator.json index 403404c80f..c59ee0ef1e 100644 --- a/tests/translator/output/api_request_model_with_validator.json +++ b/tests/translator/output/api_request_model_with_validator.json @@ -1,829 +1,829 @@ { "Resources": { - "HtmlFunctionOnlyBodyDefinitionFalse": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionOnlyBodyDefinitionFalseRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidationRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionOnlyRequestDefinitionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalseRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidation": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionNotDefinedValidationRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionNotDefinedValidation" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlFunctionMixinValidationRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentcf1c484047" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/only-request-true": { + "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" - } - }, - "x-amazon-apigateway-request-validator": "params-only", - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-and-params", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-and-params" + } + }, + "/mixin": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/mixin": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionMixinValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-only", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-only" + } + }, + "/no-validation": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-request-false": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/not-defined": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-body-true": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-only", - "responses": {}, + } + } + }, + "/only-body-false": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/not-defined": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" } - }, - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/only-body-true": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/no-validation": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-only" + } + }, + "/only-request-false": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-body-false": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/only-request-true": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "params-only" } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-request-validators": { - "params-only": { - "validateRequestParameters": true, - "validateRequestBody": false - }, "body-and-params": { - "validateRequestParameters": true, - "validateRequestBody": true - }, - "no-validation": { - "validateRequestParameters": false, - "validateRequestBody": false - }, + "validateRequestBody": true, + "validateRequestParameters": true + }, "body-only": { - "validateRequestParameters": false, - "validateRequestBody": true + "validateRequestBody": true, + "validateRequestParameters": false + }, + "no-validation": { + "validateRequestBody": false, + "validateRequestParameters": false + }, + "params-only": { + "validateRequestBody": false, + "validateRequestParameters": true } - }, - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" - } - } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentcf1c484047": { + "Properties": { + "Description": "RestApi deployment id: cf1c4840474016f8258f9b83ddb9292d01a2d7ad", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentcf1c484047" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionMixinValidation": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionMixinValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionMixinValidationGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionMixinValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] } - } - }, - "HtmlFunctionOnlyBodyDefinitionFalseRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionMixinValidationRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalse": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionNoValidation": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionOnlyRequestDefinitionFalseRole", + "HtmlFunctionNoValidationRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionNoValidationGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNoValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionNoValidationRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionNotDefinedValidation": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionNotDefinedValidationRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionNoValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionNoValidation" - }, + "Ref": "HtmlFunctionNotDefinedValidation" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionNotDefinedValidationRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionOnlyRequestDefinition" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } - }, - "HtmlFunctionOnlyRequestDefinition": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionOnlyRequestDefinitionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionNoValidation": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyBodyDefinition": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionNoValidationRole", + "HtmlFunctionOnlyBodyDefinitionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinition": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyBodyDefinitionFalse": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionOnlyBodyDefinitionRole", + "HtmlFunctionOnlyBodyDefinitionFalseRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" - }, + "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionNoValidationRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyBodyDefinitionFalseRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionMixinValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionMixinValidation" - }, + "Ref": "HtmlFunctionOnlyBodyDefinition" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionMixinValidation": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyBodyDefinitionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyRequestDefinition": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionMixinValidationRole", + "HtmlFunctionOnlyRequestDefinitionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlApiDeploymentcf1c484047": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyRequestDefinitionFalse": { "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: cf1c4840474016f8258f9b83ddb9292d01a2d7ad", - "StageName": "Stage" - } - }, - "HtmlFunctionOnlyBodyDefinitionRole": { - "Type": "AWS::IAM::Role", + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyRequestDefinitionFalseRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" - }, + "Ref": "HtmlFunctionOnlyRequestDefinition" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyRequestDefinitionRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionOnlyBodyDefinition" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_request_model_with_validator_openapi_3.json b/tests/translator/output/api_request_model_with_validator_openapi_3.json index 2e52f132f5..c8a1f2ca22 100644 --- a/tests/translator/output/api_request_model_with_validator_openapi_3.json +++ b/tests/translator/output/api_request_model_with_validator_openapi_3.json @@ -1,85 +1,27 @@ { "Resources": { - "HtmlApiDeploymentafd82ad9d8": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: afd82ad9d87f63f99528abd3b6668b168b5e49d7" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentafd82ad9d8" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "schemas": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { "/": { "get": { @@ -90,65 +32,123 @@ "$ref": "#/components/schemas/user" } } - }, + }, "required": true - }, + }, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-and-params", - "responses": {} + }, + "x-amazon-apigateway-request-validator": "body-and-params" } } - }, - "openapi": "3.0", - "components": { - "schemas": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" - } - } - } - } - }, + }, "x-amazon-apigateway-request-validators": { "body-and-params": { - "validateRequestParameters": true, - "validateRequestBody": true + "validateRequestBody": true, + "validateRequestParameters": true } } } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentafd82ad9d8": { + "Properties": { + "Description": "RestApi deployment id: afd82ad9d87f63f99528abd3b6668b168b5e49d7", + "RestApiId": { + "Ref": "HtmlApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentafd82ad9d8" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_rest_paths_with_if_condition_openapi.json b/tests/translator/output/api_rest_paths_with_if_condition_openapi.json index 75b9521f7a..b344ff6fd0 100644 --- a/tests/translator/output/api_rest_paths_with_if_condition_openapi.json +++ b/tests/translator/output/api_rest_paths_with_if_condition_openapi.json @@ -1,178 +1,110 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentdd0af0635c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiDeploymentdd0af0635c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: dd0af0635cf0797adb5e55505bff8349ddcfe008", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, "info": { "title": { "Fn::Sub": "${AWS::StackName}-Api" } }, + "openapi": "3.0", "paths": { "/post": { "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +113,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,57 +133,52 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] - } - }, - { - "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "1.0", "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, + "uri": "https://www.otherURI.co/" + } + } + }, + { "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -255,13 +187,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -270,55 +207,118 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentdd0af0635c": { + "Properties": { + "Description": "RestApi deployment id: dd0af0635cf0797adb5e55505bff8349ddcfe008", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" } } - } + ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentdd0af0635c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_else_case.json b/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_else_case.json index 7128d98067..ad2ee09076 100644 --- a/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_else_case.json +++ b/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_else_case.json @@ -1,33 +1,190 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": { + "Fn::Join": [ + ",", + [ + "www.amazon.com", + "www.google.com" + ] + ] + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, "MyApiDeployment0f6a89da8b": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 0f6a89da8bf24151eeb6b4041d5561bcc29537e4", "RestApiId": { "Ref": "MyApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment0f6a89da8b" @@ -36,10 +193,10 @@ "Ref": "MyApi" }, "StageName": "dev" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -59,36 +216,12 @@ "Value": "SAM" } ] - } - }, - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -101,7 +234,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -112,142 +246,8 @@ "Value": "SAM" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, - "options": { - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": { - "Fn::Join": [ - ",", - [ - "www.amazon.com", - "www.google.com" - ] - ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, - "summary": "CORS support", - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ], - "consumes": [ - "application/json" - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_then_case.json b/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_then_case.json index e7d4d9513f..00f2cbe4c6 100644 --- a/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_then_case.json +++ b/tests/translator/output/api_rest_paths_with_if_condition_openapi_no_value_then_case.json @@ -1,23 +1,167 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "Ref": "AWS::NoValue" + }, + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": { + "Fn::Join": [ + ",", + [ + "www.amazon.com", + "www.google.com" + ] + ] + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment517aff8ea7": { + "Properties": { + "Description": "RestApi deployment id: 517aff8ea7a3e6442006b450cc4856b4afe7fe47", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -37,10 +181,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment517aff8ea7" @@ -49,10 +193,10 @@ "Ref": "MyApi" }, "StageName": "dev" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -72,13 +216,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -91,7 +234,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -102,152 +246,8 @@ "Value": "SAM" } ] - } - }, - "MyApiDeployment517aff8ea7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 517aff8ea7a3e6442006b450cc4856b4afe7fe47", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "Ref": "AWS::NoValue" - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, - "options": { - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": { - "Fn::Join": [ - ",", - [ - "www.amazon.com", - "www.google.com" - ] - ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, - "summary": "CORS support", - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ], - "consumes": [ - "application/json" - ] - } - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_rest_paths_with_if_condition_swagger.json b/tests/translator/output/api_rest_paths_with_if_condition_swagger.json index 017f379dd2..03d1b0a282 100644 --- a/tests/translator/output/api_rest_paths_with_if_condition_swagger.json +++ b/tests/translator/output/api_rest_paths_with_if_condition_swagger.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymenta2f95cf6c6" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyApiDeploymenta2f95cf6c6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: a2f95cf6c6cded2d08c802cc1c3ecf5e8c93c81e", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -128,51 +29,43 @@ "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +74,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,57 +94,52 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] - } - }, - { - "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "1.0", "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, + "uri": "https://www.otherURI.co/" + } + } + }, + { "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -255,13 +148,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -270,27 +168,29 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -305,18 +205,118 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymenta2f95cf6c6": { + "Properties": { + "Description": "RestApi deployment id: a2f95cf6c6cded2d08c802cc1c3ecf5e8c93c81e", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymenta2f95cf6c6" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_else_case.json b/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_else_case.json index c7fd856cd4..945c3449d4 100644 --- a/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_else_case.json +++ b/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_else_case.json @@ -1,33 +1,165 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": { + "Fn::Join": [ + ",", + [ + "www.amazon.com", + "www.google.com" + ] + ] + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "securityDefinitions": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, "MyApiDeployment4cb7772053": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 4cb77720534f1e01dd19505971d13dae3adeab53", "RestApiId": { "Ref": "MyApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -47,10 +179,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment4cb7772053" @@ -59,10 +191,10 @@ "Ref": "MyApi" }, "StageName": "dev" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -82,13 +214,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -101,7 +232,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -112,140 +244,8 @@ "Value": "SAM" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, - "options": { - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": { - "Fn::Join": [ - ",", - [ - "www.amazon.com", - "www.google.com" - ] - ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, - "summary": "CORS support", - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ], - "consumes": [ - "application/json" - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_then_case.json b/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_then_case.json index 592601fb82..6a02a4245c 100644 --- a/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_then_case.json +++ b/tests/translator/output/api_rest_paths_with_if_condition_swagger_no_value_then_case.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment111c760fa1" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiDeployment111c760fa1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 111c760fa12d6d0063462b3cae3cdd6efb33fbe9", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -131,51 +32,43 @@ "Ref": "AWS::NoValue" }, { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -184,13 +77,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -199,27 +97,29 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -234,18 +134,118 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment111c760fa1": { + "Properties": { + "Description": "RestApi deployment id: 111c760fa12d6d0063462b3cae3cdd6efb33fbe9", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment111c760fa1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_swagger_integration_with_ref_intrinsic_api_id.json b/tests/translator/output/api_swagger_integration_with_ref_intrinsic_api_id.json index ce0e2e7ab0..b88a28f40a 100644 --- a/tests/translator/output/api_swagger_integration_with_ref_intrinsic_api_id.json +++ b/tests/translator/output/api_swagger_integration_with_ref_intrinsic_api_id.json @@ -1,164 +1,164 @@ { "Resources": { - "HtmlApiDeployment72be896056": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: 72be896056aaf46ddbba3a4726d528b56599d1a7", - "StageName": "Stage" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment72be896056" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "HtmlApi" - } - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "123456" + ] + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/", + "execute-api:/${__Stage__}/GET/", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": { - "AWS": [ - "123456" - ] - } - } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } + ] + }, + "Version": "2012-10-17" } } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeployment72be896056": { + "Properties": { + "Description": "RestApi deployment id: 72be896056aaf46ddbba3a4726d528b56599d1a7", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment72be896056" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_swagger_integration_with_string_api_id.json b/tests/translator/output/api_swagger_integration_with_string_api_id.json index 8d46855d1b..d562e5f419 100644 --- a/tests/translator/output/api_swagger_integration_with_string_api_id.json +++ b/tests/translator/output/api_swagger_integration_with_string_api_id.json @@ -1,162 +1,162 @@ { "Resources": { - "HtmlApiDeployment72be896056": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: 72be896056aaf46ddbba3a4726d528b56599d1a7", - "StageName": "Stage" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment72be896056" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "123456" + ] + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/", + "execute-api:/${__Stage__}/GET/", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": { - "AWS": [ - "123456" - ] - } - } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } + ] + }, + "Version": "2012-10-17" } } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeployment72be896056": { + "Properties": { + "Description": "RestApi deployment id: 72be896056aaf46ddbba3a4726d528b56599d1a7", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment72be896056" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_access_log_setting.json b/tests/translator/output/api_with_access_log_setting.json index 1b3659eda9..84701d59ad 100644 --- a/tests/translator/output/api_with_access_log_setting.json +++ b/tests/translator/output/api_with_access_log_setting.json @@ -1,7 +1,41 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "AccessLogSetting": { + "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", + "Format": "$context.requestId" + }, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,151 +51,117 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "AccessLogSetting": { - "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", - "Format": "$context.requestId" - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "AccessLogSetting": { - "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", - "Format": "$context.requestId" - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment62b96c1a61" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment62b96c1a61": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment62b96c1a61": { + "Properties": { + "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "AccessLogSetting": { + "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", + "Format": "$context.requestId" + }, + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62b96c1a61" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_any_method_in_swagger.json b/tests/translator/output/api_with_any_method_in_swagger.json index c4f81f32b2..2860f2dc27 100644 --- a/tests/translator/output/api_with_any_method_in_swagger.json +++ b/tests/translator/output/api_with_any_method_in_swagger.json @@ -1,100 +1,12 @@ { "Resources": { - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "security": [ - { - "LambdaAuthorizer": [] - } - ], - "responses": {} - } - }, - "/": { - "any": { - "x-amazon-apigateway-integration": { - "httpMethod": "ANY", - "type": "http_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "LambdaAuthorizer": [] - } - ] - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "LambdaAuthorizer": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "LambdaAuthorizer": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": null - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ "HttpApiFunctionRole", @@ -104,38 +16,16 @@ "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -148,21 +38,140 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "LambdaAuthorizer": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": null + } + ] + }, + "identitySource": "method.request.header.Authorization", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuthorizer": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } + } + }, + "/": { + "any": { + "security": [ + { + "LambdaAuthorizer": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "payloadFormatVersion": "1.0", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/" + } + }, + "get": { + "responses": {}, + "security": [ + { + "LambdaAuthorizer": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment69a80e7382": { + "Properties": { + "Description": "RestApi deployment id: 69a80e738222706cff079ab8d7f348c0d89eddab", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment69a80e7382" @@ -173,17 +182,8 @@ "StageName": { "Ref": "Stage" } - } - }, - "MyApiDeployment69a80e7382": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 69a80e738222706cff079ab8d7f348c0d89eddab", - "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_apikey_default_override.json b/tests/translator/output/api_with_apikey_default_override.json index 7152b7c9a2..456cd67ff6 100644 --- a/tests/translator/output/api_with_apikey_default_override.json +++ b/tests/translator/output/api_with_apikey_default_override.json @@ -1,318 +1,318 @@ { - "Resources": { - "MyApiWithAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAuthDeployment054e605502" - }, - "RestApiId": { - "Ref": "MyApiWithAuth" - }, - "StageName": "Prod" - } - }, - "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredTrue" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" + "Resources": { + "MyApiWithAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyDefault": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredDefault.Arn}/invocations" + } } } - ] - } - } - }, - "MyFunctionWithApiKeyRequiredFalseMyApiWithApiKeyRequiredFalsePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredFalse" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyFalse", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" + }, + "/ApiKeyFalse": { + "get": { + "responses": {}, + "security": [], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredFalse.Arn}/invocations" + } } } - ] - } + }, + "/ApiKeyTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" } }, - "MyFunctionWithApiKeyRequiredTrue": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithApiKeyRequiredTrueRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAuthDeployment054e605502": { + "Properties": { + "Description": "RestApi deployment id: 054e60550295973114b1bc4384d00c8b641ea20f", + "RestApiId": { + "Ref": "MyApiWithAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAuthDeployment054e605502" + }, + "RestApiId": { + "Ref": "MyApiWithAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionWithApiKeyRequiredDefault": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithApiKeyRequiredDefaultRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredDefaultMyApiWithApiKeyRequiredDefaultPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredDefault" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyDefault", { - "Value": "SAM", - "Key": "lambda:createdBy" + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" } ] } - }, - "MyFunctionWithApiKeyRequiredDefault": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithApiKeyRequiredDefaultRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithApiKeyRequiredDefaultRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithApiKeyRequiredFalse": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithApiKeyRequiredFalseRole", + "Arn" ] - } - }, - "MyFunctionWithApiKeyRequiredDefaultMyApiWithApiKeyRequiredDefaultPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredDefault" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyDefault", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" - } - } - ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, - "MyApiWithAuthDeployment054e605502": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAuth" - }, - "Description": "RestApi deployment id: 054e60550295973114b1bc4384d00c8b641ea20f", - "StageName": "Stage" - } - }, - "MyFunctionWithApiKeyRequiredFalse": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithApiKeyRequiredFalseRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredFalseMyApiWithApiKeyRequiredFalsePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyFalse", { - "Value": "SAM", - "Key": "lambda:createdBy" + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" } ] } - }, - "MyFunctionWithApiKeyRequiredFalseRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithApiKeyRequiredFalseRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] - } - } - }, - "MyFunctionWithApiKeyRequiredDefaultRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "MyFunctionWithApiKeyRequiredTrueRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithApiKeyRequiredTrue": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithApiKeyRequiredTrueRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredTrue" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", + { + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" + } + ] } - }, - "MyApiWithAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyFalse": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredFalse.Arn}/invocations" - } - }, - "security": [], - "responses": {} - } - }, - "/ApiKeyTrue": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - }, - "/ApiKeyDefault": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredDefault.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithApiKeyRequiredTrueRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } } +} diff --git a/tests/translator/output/api_with_apikey_required.json b/tests/translator/output/api_with_apikey_required.json index 170dd25aee..c93d398333 100644 --- a/tests/translator/output/api_with_apikey_required.json +++ b/tests/translator/output/api_with_apikey_required.json @@ -1,7 +1,85 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyRequiredTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + }, + "/any/ApiKeyRequiredTrue": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeploymentc47cf7fb87": { + "Properties": { + "Description": "RestApi deployment id: c47cf7fb87aa0c8e202c94eeb1f86c9cdc06e837", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeploymentc47cf7fb87" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithApiKeyRequired": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +99,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithApiKeyRequiredRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +111,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +120,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +132,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,86 +141,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithApiKeyRequiredRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyRequiredTrue": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/ApiKeyRequiredTrue": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiWithoutAuthDeploymentc47cf7fb87": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: c47cf7fb87aa0c8e202c94eeb1f86c9cdc06e837", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeploymentc47cf7fb87" - }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_apikey_required_openapi_3.json b/tests/translator/output/api_with_apikey_required_openapi_3.json index bd07b57de5..a1f98557d1 100644 --- a/tests/translator/output/api_with_apikey_required_openapi_3.json +++ b/tests/translator/output/api_with_apikey_required_openapi_3.json @@ -1,7 +1,86 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/ApiKeyRequiredTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + }, + "/any/ApiKeyRequiredTrue": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeploymentb2fabd579c": { + "Properties": { + "Description": "RestApi deployment id: b2fabd579c4423986c964662a3c726a321db962e", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeploymentb2fabd579c" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithApiKeyRequired": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +100,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithApiKeyRequiredRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +112,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +121,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +133,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,87 +142,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithApiKeyRequiredRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyRequiredTrue": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/ApiKeyRequiredTrue": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - } - }, - "MyApiWithoutAuthDeploymentb2fabd579c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: b2fabd579c4423986c964662a3c726a321db962e", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - } - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeploymentb2fabd579c" + ], + "Version": "2012-10-17" }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_apikey_source.json b/tests/translator/output/api_with_apikey_source.json index 1e5bd9e57c..7bd7a494d7 100644 --- a/tests/translator/output/api_with_apikey_source.json +++ b/tests/translator/output/api_with_apikey_source.json @@ -1,7 +1,57 @@ { "Resources": { + "MyApiWithAuthSource": { + "Properties": { + "ApiKeySourceType": "AUTHORIZER", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAuthSourceDeployment3febcdd011": { + "Properties": { + "Description": "RestApi deployment id: 3febcdd011fdd1feeb91bc6a1e04bd43987accd3", + "RestApiId": { + "Ref": "MyApiWithAuthSource" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiWithAuthSourceProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithAuthSourceDeployment3febcdd011" @@ -10,37 +60,16 @@ "Ref": "MyApiWithAuthSource" }, "StageName": "Prod" - } - }, - "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredTrue" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuthSource" - } - } - ] - } - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyFunctionWithApiKeyRequiredTrue": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionWithApiKeyRequiredTrueRole", @@ -50,27 +79,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithAuthSourceDeployment3febcdd011": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { "Properties": { - "Description": "RestApi deployment id: 3febcdd011fdd1feeb91bc6a1e04bd43987accd3", - "RestApiId": { - "Ref": "MyApiWithAuthSource" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredTrue" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", + { + "__ApiId__": { + "Ref": "MyApiWithAuthSource" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredTrueRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -83,7 +122,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -94,48 +134,8 @@ "Value": "SAM" } ] - } - }, - "MyApiWithAuthSource": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "ApiKeySourceType": "AUTHORIZER", - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyTrue": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_auth_all_maximum.json b/tests/translator/output/api_with_auth_all_maximum.json index f6570f17c0..352c9147a3 100644 --- a/tests/translator/output/api_with_auth_all_maximum.json +++ b/tests/translator/output/api_with_auth_all_maximum.json @@ -1,331 +1,17 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { @@ -334,150 +20,156 @@ { "api_key": [] } - ] - } - }, - "/any/noauth": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/cognitomultiple": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/users": { - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/default": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyCognitoAuth": [] }, { "api_key": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdarequest": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - }, - "patch": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatoken": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + "MyLambdaTokenAuth": [] }, { "api_key": [] } - ] - }, - "delete": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatokennone": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] }, { "api_key": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/noauth": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuth": [] + "NONE": [] }, { "api_key": [] } - ] - } - }, - "/any/cognitomultiple": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/users": { + "delete": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - } - }, - "/any/lambdatoken": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "get": { "responses": {}, "security": [ { @@ -486,18 +178,16 @@ { "api_key": [] } - ] - } - }, - "/any/lambdatokennone": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "patch": { "responses": {}, "security": [ { @@ -506,38 +196,34 @@ { "api_key": [] } - ] - } - }, - "/any/lambdarequest": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/any/default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { @@ -546,45 +232,52 @@ { "api_key": [] } - ] + ], + "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" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "MyAuthorizationHeader", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "MyAuthorizationHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", + "identityValidationExpression": "myauthvalidationexpression", "providerARNs": [ "arn:aws:1" ], - "identityValidationExpression": "myauthvalidationexpression" - } + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, "MyCognitoAuthMultipleUserPools": { - "type": "apiKey", - "name": "MyAuthorizationHeader2", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "MyAuthorizationHeader2", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", + "identityValidationExpression": "myauthvalidationexpression2", "providerARNs": [ "arn:aws:2", "arn:aws:3" ], - "identityValidationExpression": "myauthvalidationexpression2" - } + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "MyCustomAuthHeader", + "MyLambdaRequestAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -593,18 +286,18 @@ } ] }, - "authorizerResultTtlInSeconds": 20, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - } + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "type": "apiKey", - "name": "Authorization", + "MyLambdaTokenAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -613,16 +306,17 @@ } ] }, - "authorizerResultTtlInSeconds": 0 - } + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuthNoneFunctionInvokeRole": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -631,95 +325,401 @@ } ] }, - "authorizerResultTtlInSeconds": 0, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4" + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment563edb7c42": { + "Properties": { + "Description": "RestApi deployment id: 563edb7c42f90929db0861af12bcd8046b8cb057", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment563edb7c42" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment563edb7c42": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 563edb7c42f90929db0861af12bcd8046b8cb057", - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment563edb7c42" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "RestApiId": { - "Ref": "MyApi" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_auth_all_maximum_openapi_3.json b/tests/translator/output/api_with_auth_all_maximum_openapi_3.json index 9e88df2ff8..26c83749dd 100644 --- a/tests/translator/output/api_with_auth_all_maximum_openapi_3.json +++ b/tests/translator/output/api_with_auth_all_maximum_openapi_3.json @@ -1,330 +1,112 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApi": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", - { - "__ApiId__": { - "Ref": "MyApi" + "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { @@ -333,150 +115,156 @@ { "api_key": [] } - ] - } - }, - "/any/noauth": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/cognitomultiple": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/users": { - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/default": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyCognitoAuth": [] }, { "api_key": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdarequest": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - }, - "patch": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatoken": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + "MyLambdaTokenAuth": [] }, { "api_key": [] } - ] - }, - "delete": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatokennone": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] }, { "api_key": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/noauth": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuth": [] + "NONE": [] }, { "api_key": [] } - ] - } - }, - "/any/cognitomultiple": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/users": { + "delete": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - } - }, - "/any/lambdatoken": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "get": { "responses": {}, "security": [ { @@ -485,18 +273,16 @@ { "api_key": [] } - ] - } - }, - "/any/lambdatokennone": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "patch": { "responses": {}, "security": [ { @@ -505,38 +291,34 @@ { "api_key": [] } - ] - } - }, - "/any/lambdarequest": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/any/default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { @@ -545,182 +327,400 @@ { "api_key": [] } + ], + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentb4703b05b7": { + "Properties": { + "Description": "RestApi deployment id: b4703b05b7aed5e2b44438e65cf9811d3f0d6adc", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentb4703b05b7" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "MyAuthorizationHeader", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - "arn:aws:1" - ], - "identityValidationExpression": "myauthvalidationexpression" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyCognitoAuthMultipleUserPools": { - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "identityValidationExpression": "myauthvalidationexpression2" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "MyCustomAuthHeader", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 20, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 0 - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 0, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", + { + "__ApiId__": { + "Ref": "MyApi" }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } + "__Stage__": "*" } - } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeploymentb4703b05b7": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { "Properties": { - "Description": "RestApi deployment id: b4703b05b7aed5e2b44438e65cf9811d3f0d6adc", - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentb4703b05b7" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "RestApiId": { - "Ref": "MyApi" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_auth_all_minimum.json b/tests/translator/output/api_with_auth_all_minimum.json index a64255ce5a..fa00f9d083 100644 --- a/tests/translator/output/api_with_auth_all_minimum.json +++ b/tests/translator/output/api_with_auth_all_minimum.json @@ -1,57 +1,55 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { + "/any/cognito": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { + "responses": {}, "security": [ { "MyCognitoAuth": [] } ], - "responses": {} - } - }, - "/any/cognito": { - "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/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -65,100 +63,85 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithCognitoAuthDeploymentdcc28e4b5f": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment6a32cc7f63" - }, + "Description": "RestApi deployment id: dcc28e4b5f8fbdb114c4da86eae5deddc368c60e", "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" }, - "StageName": "Prod" - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiWithCognitoAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeploymentdcc28e4b5f" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/any/lambda-request": { "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-request": { + "get": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } ], - "responses": {} - } - }, - "/lambda-request": { - "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyLambdaRequestAuth": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -171,212 +154,114 @@ } } ] - } + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } - }, - "MyApiWithLambdaTokenAuthDeployment03cc3fd4fd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: 03cc3fd4fd00e795fb067f94da06cb2fcfe95d3b", - "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithCognitoAuthDeploymentdcc28e4b5f": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiWithLambdaRequestAuthDeployment6a32cc7f63": { "Properties": { + "Description": "RestApi deployment id: 6a32cc7f63485b93190f441a47da57f43de6a532", "RestApiId": { - "Ref": "MyApiWithCognitoAuth" + "Ref": "MyApiWithLambdaRequestAuth" }, - "Description": "RestApi deployment id: dcc28e4b5f8fbdb114c4da86eae5deddc368c60e", "StageName": "Stage" - } - }, - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "Schema": [ - { - "AttributeDataType": "String", - "Required": false, - "Name": "email" - } - ] - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { "Fn::GetAtt": [ - "MyAuthFnRole", + "MyAuthFn", "Arn" ] }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } } ] } - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeploymentdcc28e4b5f" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithNotCachedLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithLambdaRequestAuthProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuthDeployment444f67cd7c" + "Ref": "MyApiWithLambdaRequestAuthDeployment6a32cc7f63" }, "RestApiId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" + "Ref": "MyApiWithLambdaRequestAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithNotCachedLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaTokenAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/not-cached-lambda-request": { - "get": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuth": [] } ], - "responses": {} + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { + "MyLambdaTokenAuth": { "in": "header", + "name": "Authorization", "type": "apiKey", - "name": "Unused", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -389,175 +274,97 @@ } } ] - } + }, + "type": "token" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthDeployment03cc3fd4fd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "Description": "RestApi deployment id: 03cc3fd4fd00e795fb067f94da06cb2fcfe95d3b", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ "MyAuthFn", "Arn" ] }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment03cc3fd4fd" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithNotCachedLambdaRequestAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { + "/not-cached-lambda-request": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] } ], - "responses": {} - } - }, - "/any/lambda-token": { - "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/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaTokenAuth": { + "MyLambdaRequestAuth": { "in": "header", + "name": "Unused", "type": "apiKey", - "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -570,35 +377,37 @@ } } ] - } + }, + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithLambdaRequestAuthDeployment6a32cc7f63": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiWithNotCachedLambdaRequestAuthDeployment444f67cd7c": { "Properties": { + "Description": "RestApi deployment id: 444f67cd7c6475a698a0101480ba99b498325e90", "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithNotCachedLambdaRequestAuth" }, - "Description": "RestApi deployment id: 6a32cc7f63485b93190f441a47da57f43de6a532", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithNotCachedLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ "MyAuthFn", "Arn" ] }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", @@ -609,34 +418,47 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFnLambdaNotCachedRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithNotCachedLambdaRequestAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "DeploymentId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuthDeployment444f67cd7c" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-cached-lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" - } - } + "RestApiId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -649,49 +471,28 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment03cc3fd4fd" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "StageName": "Prod" - } - }, - "MyApiWithNotCachedLambdaRequestAuthDeployment444f67cd7c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" - }, - "Description": "RestApi deployment id: 444f67cd7c6475a698a0101480ba99b498325e90", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "MyFn": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFnRole", @@ -701,11 +502,210 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaNotCachedRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-cached-lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } } diff --git a/tests/translator/output/api_with_auth_all_minimum_openapi.json b/tests/translator/output/api_with_auth_all_minimum_openapi.json index 3cc8a4f8b3..20e698f588 100644 --- a/tests/translator/output/api_with_auth_all_minimum_openapi.json +++ b/tests/translator/output/api_with_auth_all_minimum_openapi.json @@ -1,340 +1,86 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucketname", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucketname", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/cognito": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "/any/cognito": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - { - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } } } } } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeployment3d7b08655b": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 3d7b08655b69587e7ecc140471014731e77306ff", "RestApiId": { "Ref": "MyApiWithCognitoAuth" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeployment3d7b08655b" @@ -343,64 +89,140 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/lambda-token": { - "get": { + "/any/lambda-request": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-request": { + "get": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] } - ] - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {}, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ] + } } } - }, - "openapi": "3.0.1", + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeploymente12f2a6380": { + "Properties": { + "Description": "RestApi deployment id: e12f2a6380194a4b680d60fcf8280f19975a6df2", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeploymente12f2a6380" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { "components": { "securitySchemes": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -413,178 +235,356 @@ } } ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } } } } } - } - } - }, - "MyApiWithLambdaTokenAuthDeployment14dd510133": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 14dd510133f6a5a3dc89de6e8f9c3ddf06471479", - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaTokenAuthDeployment14dd510133": { + "Properties": { + "Description": "RestApi deployment id: 14dd510133f6a5a3dc89de6e8f9c3ddf06471479", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment14dd510133" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucketname", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFn": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment14dd510133" + "Code": { + "S3Bucket": "bucketname", + "S3Key": "thumbnails.zip" }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnCognitoPermissionProd": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - }, - "/any/lambda-request": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } - } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeploymente12f2a6380": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: e12f2a6380194a4b680d60fcf8280f19975a6df2", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeploymente12f2a6380" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_auth_and_conditions_all_max.json b/tests/translator/output/api_with_auth_and_conditions_all_max.json index 06f9a64347..ed6523823d 100644 --- a/tests/translator/output/api_with_auth_and_conditions_all_max.json +++ b/tests/translator/output/api_with_auth_and_conditions_all_max.json @@ -2,317 +2,275 @@ "Conditions": { "PathCondition": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentf5a2efce75" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "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": {}, "security": [ { "NONE": [] } - ], - "responses": {} + ], + "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" + } + } } - }, + }, "/users": { - "put": { + "delete": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, + }, + "get": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "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" + } + } + }, "patch": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, + }, "post": { - "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": {}, "security": [ { "MyCognitoAuthMultipleUserPools": [] } - ], - "responses": {} - }, - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} - }, - "delete": { + } + }, + "put": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", + "identityValidationExpression": "myauthvalidationexpression", "providerARNs": [ "arn:aws:1" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - } - }, + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, + }, + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } - }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentf5a2efce75": { + "Properties": { + "Description": "RestApi deployment id: f5a2efce75b3ac7637faff7fe6310ec2e9bb05a8", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { "Ref": "MyApi" @@ -320,251 +278,293 @@ } ] } - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentf5a2efce75" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "MyFunctionWithConditional": { + "Condition": "PathCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithConditionalRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithConditionalRole": { + "Condition": "PathCondition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionWithConditionalWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithConditionalWithDefaultAuthorizerPermissionProd": { + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionWithConditional" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionWithConditionalWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionWithConditional" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithConditionalWithLambdaTokenAuthorizerPermissionProd": { + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithConditional" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionWithConditional": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithConditionalRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "PathCondition" - }, - "MyApiDeploymentf5a2efce75": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: f5a2efce75b3ac7637faff7fe6310ec2e9bb05a8", - "StageName": "Stage" - } - }, - "MyFunctionWithConditionalWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionWithConditional" - }, + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyFunctionWithConditionalRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" + }, + "Type": "AWS::Lambda::Permission" } } } diff --git a/tests/translator/output/api_with_auth_no_default.json b/tests/translator/output/api_with_auth_no_default.json index f03d2eee14..1f458b7c9c 100644 --- a/tests/translator/output/api_with_auth_no_default.json +++ b/tests/translator/output/api_with_auth_no_default.json @@ -1,303 +1,46 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { + "/any/cognito": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + "/cognito": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -305,25 +48,28 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeployment2e051a46ac": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 2e051a46ac5aa5cc0d75c4e1120425e22439be9f", "RestApiId": { "Ref": "MyApiWithCognitoAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeployment2e051a46ac" @@ -332,53 +78,50 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { - "get": { + "/any/lambda-request": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + "/lambda-request": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", + "MyLambdaRequestAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -391,37 +134,29 @@ } } ] - } - } + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithLambdaTokenAuthDeployment284a4a60d9": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiWithLambdaRequestAuthDeployment4f5f651644": { "Properties": { - "Description": "RestApi deployment id: 284a4a60d9b720f60d83ab6d114b98256d769d5a", + "Description": "RestApi deployment id: 4f5f651644c30d447f147bed005f544561e01954", "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Ref": "MyApiWithLambdaRequestAuth" }, "StageName": "Stage" - } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment284a4a60d9" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -436,58 +171,67 @@ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" + "Ref": "MyApiWithLambdaRequestAuth" } } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment4f5f651644" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-request": { - "get": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/lambda-request": { - "x-amazon-apigateway-any-method": { + "/lambda-token": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -501,57 +245,313 @@ } ] }, - "identitySource": "method.request.header.Authorization1" - } + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithLambdaRequestAuthDeployment4f5f651644": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiWithLambdaTokenAuthDeployment284a4a60d9": { "Properties": { - "Description": "RestApi deployment id: 4f5f651644c30d447f147bed005f544561e01954", + "Description": "RestApi deployment id: 284a4a60d9b720f60d83ab6d114b98256d769d5a", "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithLambdaTokenAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment4f5f651644" + "Ref": "MyApiWithLambdaTokenAuthDeployment284a4a60d9" }, "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithLambdaTokenAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyAuthFn": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFnRole", "Arn" ] }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", { "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_auth_with_default_scopes.json b/tests/translator/output/api_with_auth_with_default_scopes.json index ba1c3d1088..a81f9543d9 100644 --- a/tests/translator/output/api_with_auth_with_default_scopes.json +++ b/tests/translator/output/api_with_auth_with_default_scopes.json @@ -1,399 +1,399 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/cognitowithauthnone": { + "/cognitoauthorizercopesoverwritten": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [] + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [] + "MyCognitoAuthWithDefaultScopes": [] } - ], - "responses": {} - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" ] } - ], - "responses": {} - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] + "MyDefaultCognitoAuth": [] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": {}, "security": [ { "MyDefaultCognitoAuth": [ - "overwritten.read", + "overwritten.read", "overwritten.write" ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - ], - "responses": {} + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ "arn:aws:2" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ "arn:aws:1" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" } - } - }, - "MyFnCognitoDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeployment442cfe5207": { + "Properties": { + "Description": "RestApi deployment id: 442cfe52072a3a5798bee91fd7ffb9d9ac76b9ca", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment442cfe5207" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthDeployment442cfe5207": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 442cfe52072a3a5798bee91fd7ffb9d9ac76b9ca", - "StageName": "Stage" - } - }, - "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFnCognitoDefaultScopesDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoWithAuthNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment442cfe5207" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoWithAuthNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_auth_with_default_scopes_openapi.json b/tests/translator/output/api_with_auth_with_default_scopes_openapi.json index a70e837e6d..46e20fe7f4 100644 --- a/tests/translator/output/api_with_auth_with_default_scopes_openapi.json +++ b/tests/translator/output/api_with_auth_with_default_scopes_openapi.json @@ -1,400 +1,400 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuthWithDefaultScopes": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:2" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyDefaultCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/cognitowithauthnone": { + "/cognitoauthorizercopesoverwritten": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [] + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [] + "MyCognitoAuthWithDefaultScopes": [] } - ], - "responses": {} - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" ] } - ], - "responses": {} - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] + "MyDefaultCognitoAuth": [] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": {}, "security": [ { "MyDefaultCognitoAuth": [ - "overwritten.read", + "overwritten.read", "overwritten.write" ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] + "NONE": [] } - ], - "responses": {} - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:2" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } } } - } - }, - "MyFnCognitoDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeployment85cd9eefb8": { + "Properties": { + "Description": "RestApi deployment id: 85cd9eefb8a3340e269379417aec51cb16416c4f", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment85cd9eefb8" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFnCognitoDefaultScopesDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthDeployment85cd9eefb8": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 85cd9eefb8a3340e269379417aec51cb16416c4f" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoWithAuthNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment85cd9eefb8" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoWithAuthNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_aws_account_blacklist.json b/tests/translator/output/api_with_aws_account_blacklist.json index a5b504d421..28b8f24ccd 100644 --- a/tests/translator/output/api_with_aws_account_blacklist.json +++ b/tests/translator/output/api_with_aws_account_blacklist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionAnyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,85 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "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", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -146,16 +149,16 @@ } ] } - ], + ] + }, + { + "Action": "execute-api:Invoke", + "Effect": "Deny", "Principal": { "AWS": [ "12345" ] - } - }, - { - "Effect": "Deny", - "Action": "execute-api:Invoke", + }, "Resource": [ { "Fn::Sub": [ @@ -165,30 +168,26 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] } - ] + ], + "Version": "2012-10-17" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment4377b16cc6": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 4377b16cc6df576ca5315d2e7ab9a5752a3b7ef1", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment4377b16cc6" @@ -197,7 +196,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_aws_account_whitelist.json b/tests/translator/output/api_with_aws_account_whitelist.json index 59fc463b94..6af0edb93c 100644 --- a/tests/translator/output/api_with_aws_account_whitelist.json +++ b/tests/translator/output/api_with_aws_account_whitelist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionAnyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,85 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "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", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -146,16 +149,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "67890" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -165,16 +168,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "67890" - ] - } + ] }, { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -184,16 +187,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "67890" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -203,30 +206,26 @@ } ] } - ], - "Principal": { - "AWS": [ - "67890" - ] - } + ] } - ] + ], + "Version": "2012-10-17" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment71c7b72862": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 71c7b728620efd03a357cac7a004e60dd5ec9b53", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment71c7b72862" @@ -235,7 +234,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_aws_iam_auth_overrides.json b/tests/translator/output/api_with_aws_iam_auth_overrides.json index 59174643ab..fef06328ed 100644 --- a/tests/translator/output/api_with_aws_iam_auth_overrides.json +++ b/tests/translator/output/api_with_aws_iam_auth_overrides.json @@ -1,929 +1,929 @@ { "Resources": { - "MyFunctionCustomInvokeRole": { - "Type": "AWS::Lambda::Function", + "MyApiWithAwsIamAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/MyFunctionCustomInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::456::role/something-else", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCustomInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionDefaultInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionDefaultInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionMyCognitoAuth": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionMyCognitoAuth.Arn}/invocations" + } + } + } + }, + "/MyFunctionNONEInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNONEInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionNoneAuth": { + "get": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoneAuth.Arn}/invocations" + } + } + } + }, + "/MyFunctionNullInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNullInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionWithoutAuth": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::123:role/AUTH_AWS_IAM", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithoutAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + }, + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:cognito-idp:xxxxxxxxx" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthDeployment3bec5f30f2": { + "Properties": { + "Description": "RestApi deployment id: 3bec5f30f275272b5feee10af30f848d1ce4400d", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthNoCallerCredentials": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCallerCredentialsOverride.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoCallerCredentials.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthNoCallerCredentialsDeployment38c75afec1": { + "Properties": { + "Description": "RestApi deployment id: 38c75afec1f32ff6e177b0f49a2b9e86958f594e", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthNoCallerCredentialsProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentialsDeployment38c75afec1" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeployment3bec5f30f2" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionCallerCredentialsOverride": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionCustomInvokeRoleRole", + "MyFunctionCallerCredentialsOverrideRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoneAuth": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionCallerCredentialsOverrideAPI3PermissionProd": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionNoneAuthRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionCallerCredentialsOverride" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionCallerCredentialsOverrideRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRole": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionCustomInvokeRole": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNullInvokeRoleRole", + "MyFunctionCustomInvokeRoleRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeployment3bec5f30f2" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } - }, - "MyFunctionWithoutAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionCustomInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionCustomInvokeRole" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionCustomInvokeRole", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionCustomInvokeRole", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionMyCognitoAuthAPI1PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionCustomInvokeRoleRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionMyCognitoAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionMyCognitoAuth", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - ] - } - } - }, - "MyApiWithAwsIamAuthNoCallerCredentials": { - "Type": "AWS::ApiGateway::RestApi", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionDefaultInvokeRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoCallerCredentials.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCallerCredentialsOverride.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authtype": "awsSigv4" - } + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionDefaultInvokeRoleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } - }, - "MyFunctionWithoutAuthAPI2PermissionProd": { - "Type": "AWS::Lambda::Permission", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionDefaultInvokeRoleAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionWithoutAuth" - }, + "Ref": "MyFunctionDefaultInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionWithoutAuth", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionDefaultInvokeRole", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionDefaultInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionDefaultInvokeRoleRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionDefaultInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionDefaultInvokeRole", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyFunctionMyCognitoAuth": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionMyCognitoAuthRole", + "MyFunctionMyCognitoAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRoleRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionMyCognitoAuthAPI1PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionMyCognitoAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionMyCognitoAuth", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionMyCognitoAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionNONEInvokeRole": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNONEInvokeRoleRole", + "MyFunctionNONEInvokeRoleRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoCallerCredentialsAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNONEInvokeRoleAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNoCallerCredentials" - }, + "Ref": "MyFunctionNONEInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNONEInvokeRole", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - } + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNoneAuthRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNONEInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionCustomInvokeRoleRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithAwsIamAuthDeployment3bec5f30f2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "Description": "RestApi deployment id: 3bec5f30f275272b5feee10af30f848d1ce4400d", - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthNoCallerCredentialsDeployment38c75afec1": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionNoCallerCredentials": { "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - }, - "Description": "RestApi deployment id: 38c75afec1f32ff6e177b0f49a2b9e86958f594e", - "StageName": "Stage" - } - }, - "MyFunctionCallerCredentialsOverrideAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNoCallerCredentialsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNoCallerCredentialsAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionCallerCredentialsOverride" - }, + "Ref": "MyFunctionNoCallerCredentials" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNoCallerCredentialsRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - ] - } - } - }, - "MyFunctionCallerCredentialsOverride": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionCallerCredentialsOverrideRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionWithoutAuth": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNoneAuth": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionWithoutAuthRole", + "MyFunctionNoneAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionNullInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNullInvokeRole", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } - } - ] - } - } - }, - "MyFunctionNONEInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNoneAuthAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNONEInvokeRole" - }, + "Ref": "MyFunctionNoneAuth" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNONEInvokeRole", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNoneAuth", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNoCallerCredentialsRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNoneAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionDefaultInvokeRoleRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionCallerCredentialsOverrideRole": { - "Type": "AWS::IAM::Role", + "MyFunctionNullInvokeRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNullInvokeRoleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNullInvokeRoleAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionNullInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNullInvokeRole", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionMyCognitoAuthRole": { - "Type": "AWS::IAM::Role", + "MyFunctionNullInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyApiWithAwsIamAuthNoCallerCredentialsProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentialsDeployment38c75afec1" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - }, - "StageName": "Prod" - } - }, - "MyFunctionDefaultInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionDefaultInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoCallerCredentials": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithoutAuth": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNoCallerCredentialsRole", + "MyFunctionWithoutAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/MyFunctionWithoutAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithoutAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNONEInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNONEInvokeRole.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionMyCognitoAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionMyCognitoAuth.Arn}/invocations" - } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } - }, - "/MyFunctionDefaultInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionDefaultInvokeRole.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionCustomInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCustomInvokeRole.Arn}/invocations" - }, - "credentials": "arn:aws:iam::456::role/something-else" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNullInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNullInvokeRole.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNoneAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoneAuth.Arn}/invocations" - } - }, - "security": [ - { - "NONE": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:cognito-idp:xxxxxxxxx" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - } - } - }, - "MyFunctionNoneAuthAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithoutAuthAPI2PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNoneAuth" - }, + "Ref": "MyFunctionWithoutAuth" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNoneAuth", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionWithoutAuth", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNONEInvokeRoleRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithoutAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_basic_custom_domain.json b/tests/translator/output/api_with_basic_custom_domain.json index 4ed229a5a1..8e22384455 100644 --- a/tests/translator/output/api_with_basic_custom_domain.json +++ b/tests/translator/output/api_with_basic_custom_domain.json @@ -1,397 +1,397 @@ { "Parameters": { - "MyDomainName": { - "Default": "another-example.com", - "Type": "String" - }, "MyDomainCert": { - "Default": "another-api-arn", + "Default": "another-api-arn", + "Type": "String" + }, + "MyDomainName": { + "Default": "another-example.com", "Type": "String" } - }, + }, "Resources": { + "ApiGatewayDomainName23cdccdf9c": { + "Properties": { + "CertificateArn": "my-api-cert-arn", + "DomainName": "api-example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + }, + "MutualTlsAuthentication": { + "TruststoreUri": "my-api-truststore-uri", + "TruststoreVersion": "my-api-truststore-version" + }, + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "ApiGatewayDomainNameeab65c1531": { + "Properties": { + "DomainName": "another-example.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "RegionalCertificateArn": "another-api-arn" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyAnotherApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/another/get": { + "post": { + "responses": {}, + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyAnotherApiBasePathMapping": { + "Properties": { + "DomainName": { + "Ref": "ApiGatewayDomainNameeab65c1531" + }, + "RestApiId": { + "Ref": "MyAnotherApi" + }, + "Stage": { + "Ref": "MyAnotherApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyAnotherApiDeployment48a61be119": { + "Properties": { + "Description": "RestApi deployment id: 48a61be119a247807ea0ef8378e6aa16592f90fa", + "RestApiId": { + "Ref": "MyAnotherApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyAnotherApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyAnotherApiDeployment48a61be119" + }, + "RestApiId": { + "Ref": "MyAnotherApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "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" + } + } + } + }, + "/get": { + "put": { + "responses": {}, + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment347043ff9e": { + "Properties": { + "Description": "RestApi deployment id: 347043ff9ec72c6ce10317548939c3802eb1dd55", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment347043ff9e" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApifetchBasePathMapping": { + "Properties": { + "BasePath": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainName23cdccdf9c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApigetBasePathMapping": { + "Properties": { + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainName23cdccdf9c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionAnotherGetPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/another/get", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/another/get", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyAnotherApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ApiGatewayDomainName23cdccdf9c": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "my-api-cert-arn", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "MutualTlsAuthentication": { - "TruststoreUri": "my-api-truststore-uri", - "TruststoreVersion": "my-api-truststore-version" - }, - "SecurityPolicy": "TLS_1_2", - "DomainName": "api-example.com" - } - }, - "MyFunctionImplicitGetPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionApiPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", { - "__Stage__": "*", "__ApiId__": { - "Ref": "ServerlessRestApi" - } + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } - }, - "MyAnotherApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyAnotherApiDeployment48a61be119" - }, - "RestApiId": { - "Ref": "MyAnotherApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyAnotherApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitGetPermissionProd": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/another/get": { - "post": { - "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": {} - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } - }, - "openapi": "3.0.1" - } - } - }, - "MyApifetchBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "fetch", - "DomainName": { - "Ref": "ApiGatewayDomainName23cdccdf9c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" + ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApigetBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "get", - "DomainName": { - "Ref": "ApiGatewayDomainName23cdccdf9c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessRestApi": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/get": { - "put": { - "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": {} - } - }, - "/fetch": { + "/implicit": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0.1" + }, + "swagger": "2.0" } - } - }, - "MyAnotherApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiBasePathMapping": { "Properties": { "DomainName": { "Ref": "ApiGatewayDomainNameeab65c1531" - }, + }, "RestApiId": { - "Ref": "MyAnotherApi" - }, + "Ref": "ServerlessRestApi" + }, "Stage": { - "Ref": "MyAnotherApiProdStage" + "Ref": "ServerlessRestApiProdStage" } - } - }, - "ApiGatewayDomainNameeab65c1531": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "RegionalCertificateArn": "another-api-arn", - "DomainName": "another-example.com" - } - }, + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "ServerlessRestApiDeployment3c44da8ffd": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 3c44da8ffdf3025dc792391a61590b92e8e2ff48", "RestApiId": { "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 3c44da8ffdf3025dc792391a61590b92e8e2ff48", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment3c44da8ffd" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "MyApiDeployment347043ff9e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 347043ff9ec72c6ce10317548939c3802eb1dd55" - } - }, - "ServerlessRestApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainNameeab65c1531" - }, + }, "RestApiId": { "Ref": "ServerlessRestApi" - }, - "Stage": { - "Ref": "ServerlessRestApiProdStage" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment347043ff9e" - }, - "RestApiId": { - "Ref": "MyApi" - }, + }, "StageName": "Prod" - } - }, - "MyAnotherApiDeployment48a61be119": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyAnotherApi" - }, - "Description": "RestApi deployment id: 48a61be119a247807ea0ef8378e6aa16592f90fa" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/implicit": { - "post": { - "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" - } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_basic_custom_domain_http.json b/tests/translator/output/api_with_basic_custom_domain_http.json index f99b2c682e..0f2738fc65 100644 --- a/tests/translator/output/api_with_basic_custom_domain_http.json +++ b/tests/translator/output/api_with_basic_custom_domain_http.json @@ -1,37 +1,21 @@ { "Parameters": { - "MyDomainName": { - "Default": "sam-example.com", - "Type": "String" - }, "MyDomainCert": { - "Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "Type": "String" + }, + "MyDomainName": { + "Default": "sam-example.com", "Type": "String" } - }, + }, "Resources": { - "MyApibasicApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV22dbf35af54" - }, - "ApiMappingKey": "basic", - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, "ApiGatewayDomainNameV22dbf35af54": { - "Type": "AWS::ApiGatewayV2::DomainName", "Properties": { - "DomainName": "sam-example.com", + "DomainName": "sam-example.com", "DomainNameConfigurations": [ { - "CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", "EndpointType": "REGIONAL", "SecurityPolicy": "TLS_1_2" } @@ -43,190 +27,206 @@ "Tags": { "httpapi:createdBy": "SAM" } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApibeginhereApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV22dbf35af54" - }, - "ApiMappingKey": "begin-here", - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RecordSetGroup1f4f569a7e": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { "Properties": { - "HostedZoneName": "sam-example.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV22dbf35af54", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV22dbf35af54", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "sam-example.com" - } - ] - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + } + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/basic": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], + }, "servers": [ { "x-amazon-apigateway-endpoint-configuration": { "disableExecuteApiEndpoint": true } } + ], + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApibasicApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "basic", + "DomainName": { + "Ref": "ApiGatewayDomainNameV22dbf35af54" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApibeginhereApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "begin-here", + "DomainName": { + "Ref": "ApiGatewayDomainNameV22dbf35af54" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "RecordSetGroup1f4f569a7e": { + "Properties": { + "HostedZoneName": "sam-example.com.", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV22dbf35af54", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV22dbf35af54", + "RegionalHostedZoneId" + ] + } + }, + "Name": "sam-example.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_basic_custom_domain_intrinsics.json b/tests/translator/output/api_with_basic_custom_domain_intrinsics.json index 09d694c4e4..69df9e3fc8 100644 --- a/tests/translator/output/api_with_basic_custom_domain_intrinsics.json +++ b/tests/translator/output/api_with_basic_custom_domain_intrinsics.json @@ -2,18 +2,18 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { - "MyDomainCert": { - "Default": "another-api-arn", - "Type": "String" - }, "EndpointConf": { - "Default": "REGIONAL", + "Default": "REGIONAL", + "Type": "String" + }, + "MyDomainCert": { + "Default": "another-api-arn", "Type": "String" }, "MyMTLSUri": { @@ -24,310 +24,310 @@ "Default": "another-api-truststore-version", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "C1" - }, - "MyFunctionImplicitGetPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "C1" - }, "ApiGatewayDomainNamec0ed6fae34": { - "Type": "AWS::ApiGateway::DomainName", + "Condition": "C1", "Properties": { + "DomainName": { + "Fn::Sub": "example-ap-southeast-1.com" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "RegionalCertificateArn": "another-api-arn", - "DomainName": { - "Fn::Sub": "example-ap-southeast-1.com" }, "MutualTlsAuthentication": { "TruststoreUri": "another-api-truststore-uri", "TruststoreVersion": "another-api-truststore-version" }, + "RegionalCertificateArn": "another-api-arn", "SecurityPolicy": "TLS_1_2" }, - "Condition": "C1" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment43c34b4e46" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "C1" - }, - "MyApifetchBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "fetch", - "DomainName": { - "Ref": "ApiGatewayDomainNamec0ed6fae34" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "C1" - }, - "MyApigetBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "get", - "DomainName": { - "Ref": "ApiGatewayDomainNamec0ed6fae34" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, + "Type": "AWS::ApiGateway::DomainName" + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "/get": { "Fn::If": [ - "C1", + "C1", { "put": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1" + } } - }, - "Condition": "C1" - }, - "ServerlessRestApiDeployment43c34b4e46": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment19c8cf5c63": { + "Condition": "C1", "Properties": { + "Description": "RestApi deployment id: 19c8cf5c63090f12c5a96f6f57162495bed446c7", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 43c34b4e46d381101dd94b95856a2cea244411b4", - "StageName": "Stage" - }, - "Condition": "C1" - }, + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Condition": "C1", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment19c8cf5c63" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" - }, - "Condition": "C1" - }, - "MyApiDeployment19c8cf5c63": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApifetchBasePathMapping": { + "Condition": "C1", "Properties": { + "BasePath": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainNamec0ed6fae34" + }, "RestApiId": { "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 19c8cf5c63090f12c5a96f6f57162495bed446c7" - }, - "Condition": "C1" - }, + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApigetBasePathMapping": { + "Condition": "C1", + "Properties": { + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainNamec0ed6fae34" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { + "Condition": "C1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitGetPermissionProd": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Condition": "C1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/implicit": { "Fn::If": [ - "C1", + "C1", { "post": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, + }, "swagger": "2.0" } - }, - "Condition": "C1" - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment43c34b4e46": { + "Condition": "C1", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "C1" + "Description": "RestApi deployment id: 43c34b4e46d381101dd94b95856a2cea244411b4", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment43c34b4e46" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_basic_custom_domain_intrinsics_http.json b/tests/translator/output/api_with_basic_custom_domain_intrinsics_http.json index 8bc0ecf8b7..70ca73102d 100644 --- a/tests/translator/output/api_with_basic_custom_domain_intrinsics_http.json +++ b/tests/translator/output/api_with_basic_custom_domain_intrinsics_http.json @@ -2,18 +2,18 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { - "MyDomainCert": { - "Default": "another-api-arn", - "Type": "String" - }, "EndpointConf": { - "Default": "REGIONAL", + "Default": "REGIONAL", + "Type": "String" + }, + "MyDomainCert": { + "Default": "another-api-arn", "Type": "String" }, "MyMTLSUriHTTP": { @@ -24,315 +24,315 @@ "Default": "another-api-v2-truststore-version", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV2c0ed6fae34": { + "Condition": "C1", "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": { + "Fn::Sub": "example-ap-southeast-1.com" + }, + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "another-api-arn", + "EndpointType": "REGIONAL", + "SecurityPolicy": "TLS_1_2" } - ] - }, - "Condition": "C1" - }, - "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", + ], + "MutualTlsAuthentication": { + "TruststoreUri": "another-api-v2-truststore-uri", + "TruststoreVersion": "another-api-v2-truststore-version" + }, + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/implicit": { + "/get": { "Fn::If": [ - "C1", + "C1", { - "post": { + "put": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", + }, + "servers": [ + { + "x-amazon-apigateway-endpoint-configuration": { + "disableExecuteApiEndpoint": false + } + } + ], "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApifetchApiMapping": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainNameV2c0ed6fae34" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApigetApiMapping": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "get", + "DomainName": { + "Ref": "ApiGatewayDomainNameV2c0ed6fae34" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { + "Condition": "C1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermission": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionImplicitGetPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "C1", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "C1", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "C1" - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessHttpApi": { + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get": { + "/implicit": { "Fn::If": [ - "C1", + "C1", { - "put": { + "post": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ], - "servers": [ - { - "x-amazon-apigateway-endpoint-configuration": { - "disableExecuteApiEndpoint": false - } - } ] } - }, - "Condition": "C1" - }, - "MyFunctionApiPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "C1" - }, - "MyApigetApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV2c0ed6fae34" - }, - "ApiMappingKey": "get", - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "ApiGatewayDomainNameV2c0ed6fae34": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": { - "Fn::Sub": "example-ap-southeast-1.com" - }, - "DomainNameConfigurations": [ - { - "CertificateArn": "another-api-arn", - "EndpointType": "REGIONAL", - "SecurityPolicy": "TLS_1_2" - } - ], - "MutualTlsAuthentication": { - "TruststoreUri": "another-api-v2-truststore-uri", - "TruststoreVersion": "another-api-v2-truststore-version" - }, - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "Condition": "C1", "Properties": { "ApiId": { "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "C1" - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", + }, + "AutoDeploy": true, + "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" } - }, - "Condition": "C1" - }, - "MyApifetchApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV2c0ed6fae34" - }, - "ApiMappingKey": "fetch", - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_binary_media_types.json b/tests/translator/output/api_with_binary_media_types.json index 54540a60e5..5bd32280aa 100644 --- a/tests/translator/output/api_with_binary_media_types.json +++ b/tests/translator/output/api_with_binary_media_types.json @@ -1,203 +1,203 @@ { "Parameters": { "BMT": { - "Default": "image~1jpg", + "Default": "image~1jpg", "Type": "String" } - }, + }, "Resources": { + "ExplicitApi": { + "Properties": { + "BinaryMediaTypes": [ + "image~1gif", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "application~1octet-stream", + "image~1jpg" + ], + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { "Properties": { "BinaryMediaTypes": [ - "image~1gif", + "image~1gif", { "Fn::Join": [ - "~1", + "~1", [ - "image", + "image", "png" ] ] - }, - "application~1octet-stream", - "image~1jpg" - ], - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment4f3fcf6bd1" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ServerlessRestApiDeployment4f3fcf6bd1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 4f3fcf6bd13686961885c787e3a117b084ec6c3a", - "StageName": "Stage" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { + } + ], "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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", + }, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/gif", + "image/gif", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] } ] - }, - "BinaryMediaTypes": [ - "image~1gif", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - } - ] - } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment4f3fcf6bd1": { + "Properties": { + "Description": "RestApi deployment id: 4f3fcf6bd13686961885c787e3a117b084ec6c3a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment4f3fcf6bd1" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_binary_media_types_definition_body.json b/tests/translator/output/api_with_binary_media_types_definition_body.json index 6a9e500f8b..b641e2cfd6 100644 --- a/tests/translator/output/api_with_binary_media_types_definition_body.json +++ b/tests/translator/output/api_with_binary_media_types_definition_body.json @@ -1,134 +1,134 @@ { "Parameters": { "BMT": { - "Default": "image~1jpeg", + "Default": "image~1jpeg", "Type": "String" } - }, + }, "Resources": { - "ExplicitApiManagedSwaggerProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2" - }, - "RestApiId": { - "Ref": "ExplicitApiManagedSwagger" - }, - "StageName": "Prod" - } - }, - "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApiManagedSwagger" - }, - "Description": "RestApi deployment id: fe9c2c09a27ce00c2fa53d5a491cf343e6a3278e", - "StageName": "Stage" - } - }, "ExplicitApiDefinitionBody": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "BinaryMediaTypes": [ + "image~1jpeg", + "image~1jpg", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "application~1json" + ], "Body": { - "paths": {}, - "swagger": "2.0", + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/jpeg", - "image/jpg", + "image/jpeg", + "image/jpg", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] - }, + }, "application/json" ] - }, - "BinaryMediaTypes": [ - "image~1jpeg", - "image~1jpg", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - }, - "application~1json" - ] - } - }, + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ExplicitApiDefinitionBodyDeployment1f26996adb": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 1f26996adbe5077359ecb2bb0688a9cc0ae8e4fc", "RestApiId": { "Ref": "ExplicitApiDefinitionBody" - }, - "Description": "RestApi deployment id: 1f26996adbe5077359ecb2bb0688a9cc0ae8e4fc", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiDefinitionBodyProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDefinitionBodyDeployment1f26996adb" - }, + }, "RestApiId": { "Ref": "ExplicitApiDefinitionBody" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, "ExplicitApiManagedSwagger": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "BinaryMediaTypes": [ + "image~1jpeg", + "image~1jpg", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "image~1gif" + ], "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0", + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/jpeg", - "image/jpg", + "image/jpeg", + "image/jpg", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] - }, + }, "image/gif" ] - }, - "BinaryMediaTypes": [ - "image~1jpeg", - "image~1jpg", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - }, - "image~1gif" - ] - } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2": { + "Properties": { + "Description": "RestApi deployment id: fe9c2c09a27ce00c2fa53d5a491cf343e6a3278e", + "RestApiId": { + "Ref": "ExplicitApiManagedSwagger" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiManagedSwaggerProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2" + }, + "RestApiId": { + "Ref": "ExplicitApiManagedSwagger" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_canary_setting.json b/tests/translator/output/api_with_canary_setting.json index 34a7858746..5cb8bf0f8f 100644 --- a/tests/translator/output/api_with_canary_setting.json +++ b/tests/translator/output/api_with_canary_setting.json @@ -1,7 +1,45 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "CanarySetting": { + "PercentTraffic": 100, + "StageVariablesOverrides": { + "sv1": "test", + "sv2": "test2" + }, + "UseStageCache": false + }, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,159 +55,121 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ImplicitApiFunctionRole": { "Properties": { - "CanarySetting": { - "PercentTraffic": 100, - "UseStageCache": false, - "StageVariablesOverrides": { - "sv2": "test2", - "sv1": "test" - } - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "CanarySetting": { - "PercentTraffic": 100, - "UseStageCache": false, - "StageVariablesOverrides": { - "sv2": "test2", - "sv1": "test" + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment62b96c1a61" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment62b96c1a61": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", - "StageName": "Stage" - } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment62b96c1a61": { + "Properties": { + "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CanarySetting": { + "PercentTraffic": 100, + "StageVariablesOverrides": { + "sv1": "test", + "sv2": "test2" + }, + "UseStageCache": false + }, + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62b96c1a61" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_cors.json b/tests/translator/output/api_with_cors.json index cfba9bdc4e..39260d9a85 100644 --- a/tests/translator/output/api_with_cors.json +++ b/tests/translator/output/api_with_cors.json @@ -1,521 +1,521 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionAnyApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment3a5a78688c": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment3a5a78688c" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymente13d39e2d1" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymente13d39e2d1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: e13d39e2d16b8aad18f87490157d347817fa3071", - "StageName": "Stage" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment3a5a78688c": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment3a5a78688c" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/foo": { + "/": { + "get": { + "responses": {}, + "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" + } + } + }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + } + }, + "/foo": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "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": {} - } - }, - "/": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "consumes": [ - "application/json" - ], - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymente13d39e2d1": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: e13d39e2d16b8aad18f87490157d347817fa3071", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente13d39e2d1" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_cors_and_auth_no_preflight_auth.json b/tests/translator/output/api_with_cors_and_auth_no_preflight_auth.json index 678e33d5de..6a0e124704 100644 --- a/tests/translator/output/api_with_cors_and_auth_no_preflight_auth.json +++ b/tests/translator/output/api_with_cors_and_auth_no_preflight_auth.json @@ -1,302 +1,289 @@ { "Resources": { - "ServerlessApiDeploymente70e322247": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessApi" - }, - "Description": "RestApi deployment id: e70e322247bd7d33ec444c4732e7f532a222d44e", - "StageName": "Stage" - } - }, - "ServerlessApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - }, - "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - } - } - } - }, - "consumes": [ - "application/json" - ], - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - } - }, - "ApiFunctionRole": { - "Type": "AWS::IAM::Role", + "ApiFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessApiDeploymente70e322247" - }, - "RestApiId": { - "Ref": "ServerlessApi" - }, - "StageName": "Prod" - } - }, - "ApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionPostHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiFunctionRole": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyAuthFnRole", + "MyAuthFnRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + }, + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessApiDeploymente70e322247": { + "Properties": { + "Description": "RestApi deployment id: e70e322247bd7d33ec444c4732e7f532a222d44e", + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ServerlessApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { "Ref": "ServerlessApi" @@ -304,7 +291,20 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessApiDeploymente70e322247" + }, + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_cors_and_auth_preflight_auth.json b/tests/translator/output/api_with_cors_and_auth_preflight_auth.json index 4a9d4629e6..afe5a3b60c 100644 --- a/tests/translator/output/api_with_cors_and_auth_preflight_auth.json +++ b/tests/translator/output/api_with_cors_and_auth_preflight_auth.json @@ -1,7 +1,6 @@ { "Resources": { "ApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessApi" @@ -93,10 +62,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +74,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "ServerlessApi" @@ -114,10 +83,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -137,13 +136,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -156,7 +154,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -167,85 +166,50 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] - }, - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } } @@ -255,80 +219,112 @@ { "MyLambdaRequestAuth": [] } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] - }, + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + }, + "/any": { "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -342,37 +338,28 @@ } ] }, - "identitySource": "method.request.header.Authorization1" - } + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessApiDeployment4aa96ccd97": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 4aa96ccd971260f4d80fdd6f49d4377196c3ecaa", "RestApiId": { "Ref": "ServerlessApi" }, "StageName": "Stage" - } - }, - "ServerlessApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessApiDeployment4aa96ccd97" - }, - "RestApiId": { - "Ref": "ServerlessApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -392,7 +379,20 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessApiDeployment4aa96ccd97" + }, + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_and_conditions_no_definitionbody.json b/tests/translator/output/api_with_cors_and_conditions_no_definitionbody.json index 76f91c08f3..f53c122e07 100644 --- a/tests/translator/output/api_with_cors_and_conditions_no_definitionbody.json +++ b/tests/translator/output/api_with_cors_and_conditions_no_definitionbody.json @@ -9,8 +9,226 @@ } }, "Resources": { - "ImplicitApiFunction2": { - "Type": "AWS::Lambda::Function", + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "delete": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction2.Arn}/invocations" + } + } + }, + "get": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'www.example.com'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "/any": { + "Fn::If": [ + "MyCondition", + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'www.example.com'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentd48b267250": { + "Properties": { + "Description": "RestApi deployment id: d48b2672506d5937bfde8356b3c5c2866eb85f11", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentd48b267250" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Condition": "MyCondition", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,7 +237,7 @@ "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunction2Role", + "ImplicitApiFunctionRole", "Arn" ] }, @@ -30,40 +248,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunction2Role": { - "Type": "AWS::IAM::Role", + "ImplicitApiFunction2": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunction2Role", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunction2DeleteHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -81,38 +292,12 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Condition": "MyCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Condition": "MyCondition", + "ImplicitApiFunction2Role": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -125,7 +310,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -136,10 +322,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -149,7 +335,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ExplicitApi" @@ -158,10 +344,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -171,7 +357,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ExplicitApi" @@ -180,10 +366,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionPostHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -193,7 +379,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "ExplicitApi" @@ -202,225 +388,39 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { + "Condition": "MyCondition", "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "delete": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction2.Arn}/invocations" - } - }, - "responses": {} - }, - "get": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "post": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] - }, - "options": { - "summary": "CORS support", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'www.example.com'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,OPTIONS,POST'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - } - } - } } - }, - "/any": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-any-method": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "options": { - "summary": "CORS support", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'www.example.com'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - } - } - } - } - }, - { - "Ref": "AWS::NoValue" - } - ] } - } - } - } - }, - "ExplicitApiDeploymentd48b267250": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: d48b2672506d5937bfde8356b3c5c2866eb85f11", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentd48b267250" - }, - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_and_only_credentials_false.json b/tests/translator/output/api_with_cors_and_only_credentials_false.json index f7ba8c842a..e849bbabaa 100644 --- a/tests/translator/output/api_with_cors_and_only_credentials_false.json +++ b/tests/translator/output/api_with_cors_and_only_credentials_false.json @@ -1,199 +1,199 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment398246867a" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment398246867a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment398246867a": { + "Properties": { + "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment398246867a" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_and_only_headers.json b/tests/translator/output/api_with_cors_and_only_headers.json index ff15ff8eee..e7ad50c55f 100644 --- a/tests/translator/output/api_with_cors_and_only_headers.json +++ b/tests/translator/output/api_with_cors_and_only_headers.json @@ -1,353 +1,353 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment03e65d7ea2" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment602730b2df" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ExplicitApiDeployment03e65d7ea2": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 03e65d7ea2275d648803eecb7fa8e0ae7cd8f0aa", "RestApiId": { "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 03e65d7ea2275d648803eecb7fa8e0ae7cd8f0aa", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment03e65d7ea2" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ServerlessRestApiDeployment602730b2df": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionPostHtmlPermissionProd": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 602730b2df5e973b196e1b91eea6599bb11de5b4", - "StageName": "Stage" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment602730b2df": { + "Properties": { + "Description": "RestApi deployment id: 602730b2df5e973b196e1b91eea6599bb11de5b4", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment602730b2df" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_and_only_maxage.json b/tests/translator/output/api_with_cors_and_only_maxage.json index 24d3d89f76..338fa82111 100644 --- a/tests/translator/output/api_with_cors_and_only_maxage.json +++ b/tests/translator/output/api_with_cors_and_only_maxage.json @@ -1,207 +1,207 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentb61cfb7d60": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: b61cfb7d602d889bbd9867dcbf0f75d3066dcc56", - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentb61cfb7d60" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Max-Age": 600, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, + "Access-Control-Allow-Origin": { + "type": "string" + }, "Access-Control-Max-Age": { "type": "integer" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Max-Age": 600 + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Max-Age": 600, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, + "Access-Control-Allow-Origin": { + "type": "string" + }, "Access-Control-Max-Age": { "type": "integer" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Max-Age": 600 + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentb61cfb7d60": { + "Properties": { + "Description": "RestApi deployment id: b61cfb7d602d889bbd9867dcbf0f75d3066dcc56", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentb61cfb7d60" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_and_only_methods.json b/tests/translator/output/api_with_cors_and_only_methods.json index a9c8d8fc8b..9f9fcb4ab9 100644 --- a/tests/translator/output/api_with_cors_and_only_methods.json +++ b/tests/translator/output/api_with_cors_and_only_methods.json @@ -1,7 +1,6 @@ { "Resources": { "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,140 +62,170 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "methods" + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "'*'" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } } }, "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "methods" + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "'*'" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" } } } } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentcf3f77842f": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: cf3f77842fe2e5ebf6562c4d0bd1e23072711122", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentcf3f77842f" @@ -235,7 +234,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_and_only_origins.json b/tests/translator/output/api_with_cors_and_only_origins.json index c3bd97b70f..e9ba18b1fd 100644 --- a/tests/translator/output/api_with_cors_and_only_origins.json +++ b/tests/translator/output/api_with_cors_and_only_origins.json @@ -1,341 +1,341 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymenta7a992bbb6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a7a992bbb604dcd7667af3caa050bf14af2bf684", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymenta7a992bbb6" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment4be3cdc28b" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment4be3cdc28b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 4be3cdc28b991a26bed9da1180e59e9cc5467355", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta7a992bbb6": { + "Properties": { + "Description": "RestApi deployment id: a7a992bbb604dcd7667af3caa050bf14af2bf684", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymenta7a992bbb6" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment4be3cdc28b": { + "Properties": { + "Description": "RestApi deployment id: 4be3cdc28b991a26bed9da1180e59e9cc5467355", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment4be3cdc28b" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_cors_no_definitionbody.json b/tests/translator/output/api_with_cors_no_definitionbody.json index 1c5b0abff8..9a05bb7e0e 100644 --- a/tests/translator/output/api_with_cors_no_definitionbody.json +++ b/tests/translator/output/api_with_cors_no_definitionbody.json @@ -1,264 +1,147 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, - "post": { - "x-amazon-apigateway-integration": { "type": "aws_proxy", - "httpMethod": "POST", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + } + }, + "/any": { "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" } } } } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeploymenta5504ed018": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: a5504ed018ecb1b0af8d00e3a4ab4afb199541b6", "RestApiId": { "Ref": "ExplicitApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymenta5504ed018" @@ -267,7 +150,124 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_cors_openapi_3.json b/tests/translator/output/api_with_cors_openapi_3.json index c23c96f362..699d4c7aaf 100644 --- a/tests/translator/output/api_with_cors_openapi_3.json +++ b/tests/translator/output/api_with_cors_openapi_3.json @@ -1,515 +1,515 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionAnyApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } - } - } - }, "consumes": [ "application/json" ], - "summary": "CORS support", + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" ], - "summary": "CORS support", + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" - ] - }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment8cc53ffaa5": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymente3fd36e910" - }, + "Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment8cc53ffaa5" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment8cc53ffaa5": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16" - } - }, - "ServerlessRestApiDeploymente3fd36e910": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: e3fd36e910d56cf80b1b62823277d19f9b1f1a15" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { - "/foo": { + "/": { + "get": { + "responses": {}, + "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" + } + } + }, "options": { + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "schema": { + "type": "string" + } + }, + "Access-Control-Allow-Origin": { + "schema": { + "type": "string" + } + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + } + }, + "/foo": { + "options": { "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } - }, - "Access-Control-Allow-Methods": { + }, + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } - }, - "description": "Default response for CORS method" - } - } - }, - "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": {} - } - }, - "/": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - } - } - } - }, - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "schema": { - "type": "string" } }, - "Access-Control-Allow-Methods": { - "schema": { - "type": "string" - } - } - }, - "description": "Default response for CORS method" - } + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" } - }, - "get": { + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0" + } } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymente3fd36e910": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: e3fd36e910d56cf80b1b62823277d19f9b1f1a15", + "RestApiId": { + "Ref": "ServerlessRestApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente3fd36e910" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_custom_domain_route53.json b/tests/translator/output/api_with_custom_domain_route53.json index 6dc75456e4..84632ace2e 100644 --- a/tests/translator/output/api_with_custom_domain_route53.json +++ b/tests/translator/output/api_with_custom_domain_route53.json @@ -1,197 +1,197 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { + "ApiGatewayDomainName0caaf24ab1": { + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "DomainName": "example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentf643ef7f59": { + "Properties": { + "Description": "RestApi deployment id: f643ef7f592a69a57638dd25e64dc12d2b4abf2d", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentf643ef7f59" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApioneBasePathMapping": { + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "DomainName": "example.com" - } - }, - "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" - } - ] - } - }, - "MyApiDeploymentf643ef7f59": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: f643ef7f592a69a57638dd25e64dc12d2b4abf2d" - } - }, - "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "one", - "DomainName": { - "Ref": "ApiGatewayDomainName0caaf24ab1" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentf643ef7f59" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroupbd00d962a4": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "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": {} - } - } - }, - "openapi": "3.0.1" - } - } + "HostedZoneId": "ZQ1UAL4EFZVME", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json index 85799af333..fee579db64 100644 --- a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json +++ b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json @@ -1,197 +1,197 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainName0caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" + "CertificateArn": "cert-arn-in-us-east-1", + "DomainName": "example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "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" + } + } } } - ] + } } - } - }, - "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymenteb58d7577a": { "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "DomainName": "example.com" - } - }, + "Description": "RestApi deployment id: eb58d7577a65af049c9c6f10c9d8b286de6b5aeb", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeploymenteb58d7577a" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { - "BasePath": "one", + "BasePath": "one", "DomainName": { "Ref": "ApiGatewayDomainName0caaf24ab1" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "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": {} - } + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } - }, - "openapi": "3.0.1" + ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", "Properties": { - "HostedZoneName": "www.my-domain.com.", + "HostedZoneName": "www.my-domain.com.", "RecordSets": [ { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] - } - }, - "Type": "A", - "Name": "example.com" - }, + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "A" + }, { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] - } - }, - "Type": "AAAA", - "Name": "example.com" + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "AAAA" } ] - } - }, - "MyApiDeploymenteb58d7577a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: eb58d7577a65af049c9c6f10c9d8b286de6b5aeb" - } + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name_http.json b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name_http.json index d9ffc5aac4..ec5284f1db 100644 --- a/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name_http.json +++ b/tests/translator/output/api_with_custom_domain_route53_hosted_zone_name_http.json @@ -1,191 +1,191 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV20caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": "example.com", + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointType": "REGIONAL" } - ] - } - }, + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", + }, + "AutoDeploy": true, + "StageName": "Prod", "Tags": { "httpapi:createdBy": "SAM" } - } - }, + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "MyApioneApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", "Properties": { "ApiId": { "Ref": "MyApi" - }, + }, + "ApiMappingKey": "one", "DomainName": { "Ref": "ApiGatewayDomainNameV20caaf24ab1" - }, - "ApiMappingKey": "one", + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "ApiGatewayDomainNameV20caaf24ab1": { - "Type": "AWS::ApiGatewayV2::DomainName", + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { "Properties": { - "DomainName": "example.com", - "DomainNameConfigurations": [ + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointType": "REGIONAL" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneName": "www.my-domain.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFetchPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup456ebaf280": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + }, + "Name": "example.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_custom_domain_route53_http.json b/tests/translator/output/api_with_custom_domain_route53_http.json index 54e445611c..0384e8af05 100644 --- a/tests/translator/output/api_with_custom_domain_route53_http.json +++ b/tests/translator/output/api_with_custom_domain_route53_http.json @@ -1,209 +1,209 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV20caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": "example.com", + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointType": "REGIONAL" } - ] - } - }, + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "MyApioneApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", "Properties": { "ApiId": { "Ref": "MyApi" - }, + }, + "ApiMappingKey": "one", "DomainName": { "Ref": "ApiGatewayDomainNameV20caaf24ab1" - }, - "ApiMappingKey": "one", + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ApiGatewayDomainNameV20caaf24ab1": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "example.com", - "DomainNameConfigurations": [ - { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointType": "REGIONAL" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermission": { "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFetchPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroupbd00d962a4": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" + "HostedZoneId": "ZQ1UAL4EFZVME", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + }, + "Name": "example.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + }, + "Name": "example.com", + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_custom_domain_route53_multiple.json b/tests/translator/output/api_with_custom_domain_route53_multiple.json index 22f7744482..5e64d4738f 100644 --- a/tests/translator/output/api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/api_with_custom_domain_route53_multiple.json @@ -2,28 +2,31 @@ "AWSTemplateFormatVersion": "2010-09-09", "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", "Resources": { - "ApiGatewayAdminTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminOne": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminTwoDeployment61887a4eed" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminOneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName5fe29fe649" @@ -34,108 +37,132 @@ "Stage": { "Ref": "ApiGatewayAdminOneProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ApiGatewayAdminOneDeploymentdd3f545183": { + "Properties": { + "Description": "RestApi deployment id: dd3f545183668c401e771fd9a377cfeadcf88a35", + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayAdminOneProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayAdminOneDeploymentdd3f545183" }, - "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Prod", - "TracingEnabled": true, "MethodSettings": [ { "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } - }, - "ApiGatewayAdminThreeDeployment7541e97159": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7541e971598cffe7cafab030d3fccc687d508f59", - "RestApiId": { - "Ref": "ApiGatewayAdminThree" - }, - "StageName": "Stage" - } - }, - "ApiGatewayAdminOneDeploymentdd3f545183": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: dd3f545183668c401e771fd9a377cfeadcf88a35", + ], "RestApiId": { "Ref": "ApiGatewayAdminOne" }, - "StageName": "Stage" - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminThree": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminTwoDeployment61887a4eed": { - "Type": "AWS::ApiGateway::Deployment", + "ApiGatewayAdminThreeBasePathMapping": { "Properties": { - "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "DomainName": { + "Ref": "ApiGatewayDomainName41bfc7f9c4" + }, "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminThree" + }, + "Stage": { + "Ref": "ApiGatewayAdminThreeProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ApiGatewayAdminThreeDeployment7541e97159": { + "Properties": { + "Description": "RestApi deployment id: 7541e971598cffe7cafab030d3fccc687d508f59", + "RestApiId": { + "Ref": "ApiGatewayAdminThree" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiGatewayAdminThree": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayAdminThreeDeployment7541e97159" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminThree" + }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayAdminTwo": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, "swagger": "2.0" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ApiGatewayDomainName5fe29fe649": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.one.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminTwoBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName3fd2dbd8f8" @@ -146,163 +173,136 @@ "Stage": { "Ref": "ApiGatewayAdminTwoProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayAdminTwo": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminTwoDeployment61887a4eed": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" + "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiGatewayAdminTwoProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayAdminTwoDeployment61887a4eed" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, "ApiGatewayDomainName41bfc7f9c4": { - "Type": "AWS::ApiGateway::DomainName", "Properties": { - "RegionalCertificateArn": "arn::cert::abc", "DomainName": "admin.three.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } - }, - "ApiGatewayAdminThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminThreeDeployment7541e97159" }, - "RestApiId": { - "Ref": "ApiGatewayAdminThree" - }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminThreeBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayDomainName5fe29fe649": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName41bfc7f9c4" - }, - "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "DomainName": "admin.one.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "Stage": { - "Ref": "ApiGatewayAdminThreeProdStage" - } - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", "Properties": { "HostedZoneId": "abc123456", "RecordSets": [ { - "Name": "admin.two.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.two.amazon.com", + "Type": "A" }, { - "Name": "admin.three.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName41bfc7f9c4", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName41bfc7f9c4", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.three.amazon.com", + "Type": "A" }, { - "Name": "admin.one.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName5fe29fe649", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName5fe29fe649", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.one.amazon.com", + "Type": "A" } ] - } - }, - "ApiGatewayAdminOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json b/tests/translator/output/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json index 26b978e901..087c720574 100644 --- a/tests/translator/output/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json +++ b/tests/translator/output/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json @@ -7,100 +7,99 @@ } }, "Resources": { - "RecordSetGroupd9cb5a3e02": { - "Type": "AWS::Route53::RecordSetGroup", + "ApiGatewayAdminOne": { "Properties": { - "HostedZoneId": { - "Fn::Sub": "{{MyHostedZoneId}}" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "RecordSets": [ - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" - ] - } - } - } - ] - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminOneBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminTwoDeploymentca2a75b5dd" + "DomainName": { + "Ref": "ApiGatewayDomainName5fe29fe649" }, "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminOne" }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Stage": { + "Ref": "ApiGatewayAdminOneProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayDomainName5fe29fe649": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminOneDeployment066bb1ceae": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.one.amazon.com", - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "Description": "RestApi deployment id: 066bb1ceaebd0cafae99258bbe7130af8b676372", + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayAdminOneProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayAdminOneDeployment066bb1ceae" }, - "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Prod", - "TracingEnabled": true, "MethodSettings": [ { "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminThree": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminThreeBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName41bfc7f9c4" @@ -111,215 +110,216 @@ "Stage": { "Ref": "ApiGatewayAdminThreeProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayAdminOneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayAdminThreeDeployment169349c1e9": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName5fe29fe649" - }, + "Description": "RestApi deployment id: 169349c1e96a0f130ee35f7bb9d83b042c386d6f", "RestApiId": { - "Ref": "ApiGatewayAdminOne" + "Ref": "ApiGatewayAdminThree" }, - "Stage": { - "Ref": "ApiGatewayAdminOneProdStage" - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "RecordSetGroupd28e0e19d0": { - "Type": "AWS::Route53::RecordSetGroup", + "ApiGatewayAdminThreeProdStage": { "Properties": { - "HostedZoneId": { - "Ref": "MyHostedZoneId" + "DeploymentId": { + "Ref": "ApiGatewayAdminThreeDeployment169349c1e9" }, - "RecordSets": [ - { - "Name": "admin.three.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName41bfc7f9c4", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName41bfc7f9c4", - "RegionalDomainName" - ] - } - } - }, + "MethodSettings": [ { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName5fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName5fe29fe649", - "RegionalDomainName" - ] - } - } + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } - }, - "ApiGatewayAdminOneDeployment066bb1ceae": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 066bb1ceaebd0cafae99258bbe7130af8b676372", + ], "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Stage" - } - }, - "ApiGatewayAdminTwoBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName3fd2dbd8f8" - }, - "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminThree" }, - "Stage": { - "Ref": "ApiGatewayAdminTwoProdStage" - } - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, "ApiGatewayAdminTwo": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, "swagger": "2.0" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ApiGatewayDomainName41bfc7f9c4": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.three.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminTwoBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminThreeDeployment169349c1e9" + "DomainName": { + "Ref": "ApiGatewayDomainName3fd2dbd8f8" }, "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "Ref": "ApiGatewayAdminTwo" }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Stage": { + "Ref": "ApiGatewayAdminTwoProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, "ApiGatewayAdminTwoDeploymentca2a75b5dd": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: ca2a75b5dd3713c71543e80f2b6f5aac9538ea9c", "RestApiId": { "Ref": "ApiGatewayAdminTwo" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiGatewayAdminThree": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminTwoProdStage": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" + "DeploymentId": { + "Ref": "ApiGatewayAdminTwoDeploymentca2a75b5dd" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminThreeDeployment169349c1e9": { - "Type": "AWS::ApiGateway::Deployment", + "ApiGatewayDomainName41bfc7f9c4": { "Properties": { - "Description": "RestApi deployment id: 169349c1e96a0f130ee35f7bb9d83b042c386d6f", - "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "DomainName": "admin.three.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Stage" - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminOne": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayDomainName5fe29fe649": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, + "DomainName": "admin.one.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "RecordSetGroupd28e0e19d0": { + "Properties": { + "HostedZoneId": { + "Ref": "MyHostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName41bfc7f9c4", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName41bfc7f9c4", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.three.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName5fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName5fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + }, + "RecordSetGroupd9cb5a3e02": { + "Properties": { + "HostedZoneId": { + "Fn::Sub": "{{MyHostedZoneId}}" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_default_aws_iam_auth.json b/tests/translator/output/api_with_default_aws_iam_auth.json index 2e805e8af3..6e436d4973 100644 --- a/tests/translator/output/api_with_default_aws_iam_auth.json +++ b/tests/translator/output/api_with_default_aws_iam_auth.json @@ -1,168 +1,100 @@ { "Resources": { - "MyApiWithAwsIamAuthDeployment3364487a57": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "Description": "RestApi deployment id: 3364487a57573f17976c9edc5dad6c3afe02a101", - "StageName": "Stage" - } - }, - "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithAwsIamAuthRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithAwsIamAuth": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithAwsIamAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } } } - ] - } - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeployment3364487a57" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } - }, - "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeployment1edb95497c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - }, - "Description": "RestApi deployment id: 1edb95497ceb1e912fa65281f21a8f6f1098b5f4", - "StageName": "Stage" - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithAwsIamAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" } - ] + }, + "swagger": "2.0" } - } - }, - "MyApiWithAwsIamAuthAndCustomInvokeRoleDeployment61108120cf": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - }, - "Description": "RestApi deployment id: 61108120cf9f293d5cf2fc21044a94dce2ed499a", - "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithAwsIamAuthAndCustomInvokeRole": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithAwsIamAuthAndDefaultInvokeRoleProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithAwsIamAuthAndCustomInvokeRoleDeployment61108120cf": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeployment1edb95497c" - }, + "Description": "RestApi deployment id: 61108120cf9f293d5cf2fc21044a94dce2ed499a", "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" }, - "StageName": "Prod" - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithAwsIamAuthAndCustomInvokeRoleProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRoleDeployment61108120cf" @@ -171,127 +103,184 @@ "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApiWithAwsIamAuthAndDefaultInvokeRole": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "put": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - } - } - }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeployment1edb95497c": { + "Properties": { + "Description": "RestApi deployment id: 1edb95497ceb1e912fa65281f21a8f6f1098b5f4", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRoleProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeployment1edb95497c" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthDeployment3364487a57": { + "Properties": { + "Description": "RestApi deployment id: 3364487a57573f17976c9edc5dad6c3afe02a101", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeployment3364487a57" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionWithAwsIamAuth": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithAwsIamAuthRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionWithAwsIamAuth" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithAwsIamAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithAwsIamAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -304,9 +293,20 @@ ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_default_aws_iam_auth_and_no_auth_route.json b/tests/translator/output/api_with_default_aws_iam_auth_and_no_auth_route.json index dcd9745ec0..2b374255a6 100644 --- a/tests/translator/output/api_with_default_aws_iam_auth_and_no_auth_route.json +++ b/tests/translator/output/api_with_default_aws_iam_auth_and_no_auth_route.json @@ -1,7 +1,120 @@ { "Resources": { + "MyApiWithAwsIamAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/iam": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/none": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthDeployment093beda14c": { + "Properties": { + "Description": "RestApi deployment id: 093beda14c569aec5939596a6b12b8fda3695560", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeployment093beda14c" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +134,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +146,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -72,10 +155,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithNoAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +167,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -93,10 +176,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithNoAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +188,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/none", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -114,10 +197,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithNoAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithNoAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +209,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/none", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -135,121 +218,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithAwsIamAuthRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "NONE": [] - } - ] - } - }, - "/any/iam": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - } - }, - "/any/none": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "NONE": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "AWS_IAM": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - } - } - }, - "MyApiWithAwsIamAuthDeployment093beda14c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 093beda14c569aec5939596a6b12b8fda3695560", - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeployment093beda14c" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_disable_api_execute_endpoint.json b/tests/translator/output/api_with_disable_api_execute_endpoint.json index d2d3c58579..b98435a34b 100644 --- a/tests/translator/output/api_with_disable_api_execute_endpoint.json +++ b/tests/translator/output/api_with_disable_api_execute_endpoint.json @@ -1,51 +1,51 @@ { "Resources": { - "ApiGatewayApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-endpoint-configuration": { - "disableExecuteApiEndpoint": true + "Code": { + "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiGatewayApiDeploymenta13ba42368": { - "Type": "AWS::ApiGateway::Deployment", + "ApiFunctionApiEventPermissionprod": { "Properties": { - "RestApiId": { - "Ref": "ApiGatewayApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" }, - "Description": "RestApi deployment id: a13ba42368cb482635c1d715f5e0199e94d79222", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ApiGatewayApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -58,64 +58,63 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayApi": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" - }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-endpoint-configuration": { + "disableExecuteApiEndpoint": true } - ] - } + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiFunctionApiEventPermissionprod": { - "Type": "AWS::Lambda::Permission", + "ApiGatewayApiDeploymenta13ba42368": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" + "Description": "RestApi deployment id: a13ba42368cb482635c1d715f5e0199e94d79222", + "RestApiId": { + "Ref": "ApiGatewayApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ApiGatewayApi" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayApiprodStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayApiDeploymenta13ba42368" @@ -124,7 +123,8 @@ "Ref": "ApiGatewayApi" }, "StageName": "prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_fail_on_warnings.json b/tests/translator/output/api_with_fail_on_warnings.json index 6764a40802..f28cbadd4e 100644 --- a/tests/translator/output/api_with_fail_on_warnings.json +++ b/tests/translator/output/api_with_fail_on_warnings.json @@ -1,49 +1,51 @@ { "Resources": { - "ApiGatewayApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0" + "Code": { + "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" }, - "FailOnWarnings": true - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiGatewayApiDeploymentf96bc9abda": { - "Type": "AWS::ApiGateway::Deployment", + "ApiFunctionApiEventPermissionprod": { "Properties": { - "RestApiId": { - "Ref": "ApiGatewayApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" }, - "Description": "RestApi deployment id: f96bc9abdad53c001153ce8ba04f1667c7b0a004", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ApiGatewayApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,64 +58,61 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayApi": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" - }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" - ] + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "FailOnWarnings": true + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiFunctionApiEventPermissionprod": { - "Type": "AWS::Lambda::Permission", + "ApiGatewayApiDeploymentf96bc9abda": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" + "Description": "RestApi deployment id: f96bc9abdad53c001153ce8ba04f1667c7b0a004", + "RestApiId": { + "Ref": "ApiGatewayApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ApiGatewayApi" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayApiprodStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayApiDeploymentf96bc9abda" @@ -122,7 +121,8 @@ "Ref": "ApiGatewayApi" }, "StageName": "prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_gateway_responses.json b/tests/translator/output/api_with_gateway_responses.json index 21cec903c7..743e9f888d 100644 --- a/tests/translator/output/api_with_gateway_responses.json +++ b/tests/translator/output/api_with_gateway_responses.json @@ -1,79 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -81,29 +27,29 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" } } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeploymentf63e40e7e8": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f63e40e7e8923689c5fa5f296abf1fc5d4773cc3", "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: f63e40e7e8923689c5fa5f296abf1fc5d4773cc3", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymentf63e40e7e8" @@ -112,28 +58,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_gateway_responses_all.json b/tests/translator/output/api_with_gateway_responses_all.json index 2df2294464..58298b3a8b 100644 --- a/tests/translator/output/api_with_gateway_responses_all.json +++ b/tests/translator/output/api_with_gateway_responses_all.json @@ -1,79 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -88,9 +34,9 @@ }, "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", - "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", + "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", "gatewayresponse.path.PathKey": "'path-value'", "gatewayresponse.querystring.QueryStringKey": "'query-string-value'" }, @@ -99,20 +45,20 @@ } } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeploymentedbd8aa001": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: edbd8aa001b34e2c5fa4458827ad9f4075fb812d", "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: edbd8aa001b34e2c5fa4458827ad9f4075fb812d", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymentedbd8aa001" @@ -121,28 +67,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_gateway_responses_all_openapi_3.json b/tests/translator/output/api_with_gateway_responses_all_openapi_3.json index 3b90ab13e7..ea37ddc6ad 100644 --- a/tests/translator/output/api_with_gateway_responses_all_openapi_3.json +++ b/tests/translator/output/api_with_gateway_responses_all_openapi_3.json @@ -1,147 +1,147 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymenta8fcf1dd74": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a8fcf1dd7480d58309d5673300f397de4f515e47" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0", + }, "x-amazon-apigateway-gateway-responses": { "QUOTA_EXCEEDED": { "responseParameters": { "gatewayresponse.header.Retry-After": "'31536000'" - }, - "responseTemplates": {}, + }, + "responseTemplates": {}, "statusCode": "429" - }, + }, "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", - "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", - "gatewayresponse.path.PathKey": "'path-value'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", + "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.path.PathKey": "'path-value'", "gatewayresponse.querystring.QueryStringKey": "'query-string-value'" - }, - "responseTemplates": {}, + }, + "responseTemplates": {}, "statusCode": "401" } } } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta8fcf1dd74": { + "Properties": { + "Description": "RestApi deployment id: a8fcf1dd7480d58309d5673300f397de4f515e47", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymenta8fcf1dd74" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_gateway_responses_implicit.json b/tests/translator/output/api_with_gateway_responses_implicit.json index f2ac689f1f..42a5d15a89 100644 --- a/tests/translator/output/api_with_gateway_responses_implicit.json +++ b/tests/translator/output/api_with_gateway_responses_implicit.json @@ -1,13 +1,12 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionRole", @@ -17,36 +16,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ServerlessRestApiDeploymentf63e40e7e8": { - "Type": "AWS::ApiGateway::Deployment", + "FunctionGetHtmlPermissionProd": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" }, - "Description": "RestApi deployment id: f63e40e7e8923689c5fa5f296abf1fc5d4773cc3", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -59,64 +59,41 @@ ] } } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentf63e40e7e8" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" + ], + "Version": "2012-10-17" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -124,9 +101,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -134,7 +111,30 @@ } }, "Name": "some api" - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentf63e40e7e8": { + "Properties": { + "Description": "RestApi deployment id: f63e40e7e8923689c5fa5f296abf1fc5d4773cc3", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentf63e40e7e8" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_gateway_responses_minimal.json b/tests/translator/output/api_with_gateway_responses_minimal.json index 7ce2bfc307..ee743ed079 100644 --- a/tests/translator/output/api_with_gateway_responses_minimal.json +++ b/tests/translator/output/api_with_gateway_responses_minimal.json @@ -1,79 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -85,20 +31,20 @@ } } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeployment43cede1065": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 43cede1065157a0a0bdea5f4025a38449a7c37e6", "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: 43cede1065157a0a0bdea5f4025a38449a7c37e6", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment43cede1065" @@ -107,28 +53,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_gateway_responses_string_status_code.json b/tests/translator/output/api_with_gateway_responses_string_status_code.json index 21cec903c7..743e9f888d 100644 --- a/tests/translator/output/api_with_gateway_responses_string_status_code.json +++ b/tests/translator/output/api_with_gateway_responses_string_status_code.json @@ -1,79 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -81,29 +27,29 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" } } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeploymentf63e40e7e8": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f63e40e7e8923689c5fa5f296abf1fc5d4773cc3", "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: f63e40e7e8923689c5fa5f296abf1fc5d4773cc3", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymentf63e40e7e8" @@ -112,28 +58,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_identity_intrinsic.json b/tests/translator/output/api_with_identity_intrinsic.json index 32c8b8eaaf..3c6c263363 100644 --- a/tests/translator/output/api_with_identity_intrinsic.json +++ b/tests/translator/output/api_with_identity_intrinsic.json @@ -5,24 +5,21 @@ }, "Resources": { "APIGateway": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, - "swagger": "2.0", "securityDefinitions": { "SomeAuthorizer": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerResultTtlInSeconds": { "Fn::If": [ "isProd", @@ -30,7 +27,6 @@ 0 ] }, - "identitySource": "method.request.header.Accept", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -38,44 +34,29 @@ "__FunctionArn__": "SomeArn" } ] - } + }, + "identitySource": "method.request.header.Accept", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } - } - } - }, - "APIGatewaySomeAuthorizerAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "SomeArn", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "APIGateway" - } - } - ] + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "APIGatewayDeploymenta119f04c8a": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: a119f04c8aba206b5b7db5f232f013b816fe6447", "RestApiId": { "Ref": "APIGateway" }, - "Description": "RestApi deployment id: a119f04c8aba206b5b7db5f232f013b816fe6447", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "APIGatewayProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "APIGatewayDeploymenta119f04c8a" @@ -84,7 +65,26 @@ "Ref": "APIGateway" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "APIGatewaySomeAuthorizerAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "SomeArn", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "APIGateway" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" } } } diff --git a/tests/translator/output/api_with_if_conditional_with_resource_policy.json b/tests/translator/output/api_with_if_conditional_with_resource_policy.json index fe98c4f2a2..5319408848 100644 --- a/tests/translator/output/api_with_if_conditional_with_resource_policy.json +++ b/tests/translator/output/api_with_if_conditional_with_resource_policy.json @@ -8,8 +8,98 @@ } }, "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/one": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/three": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/two": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Fn::If": [ + "C1", + { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "Version": "2012-10-17" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment8041a8ddc7": { + "Properties": { + "Description": "RestApi deployment id: 8041a8ddc7a29838548794b950dd519113e31442", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -29,40 +119,10 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "ExplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -80,10 +140,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "ExplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -101,10 +161,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPutHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -113,7 +173,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", { "__ApiId__": { "Ref": "ExplicitApi" @@ -122,10 +182,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPutHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -134,7 +194,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", { "__ApiId__": { "Ref": "ExplicitApi" @@ -143,101 +203,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ExplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Fn::If": [ - "C1", - { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - }, - { - "Ref": "AWS::NoValue" - } - ] - } - } - } - } - }, - "ExplicitApiDeployment8041a8ddc7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 8041a8ddc7a29838548794b950dd519113e31442", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment8041a8ddc7" @@ -246,7 +245,8 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_incompatible_stage_name.json b/tests/translator/output/api_with_incompatible_stage_name.json index 892f194744..d10f12d334 100644 --- a/tests/translator/output/api_with_incompatible_stage_name.json +++ b/tests/translator/output/api_with_incompatible_stage_name.json @@ -1,288 +1,288 @@ { "Resources": { - "HyphenApiDeployment19b8787883": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HyphenApi" - }, - "Description": "RestApi deployment id: 19b8787883c74d792cf1ba94de3fd550cf820694", - "StageName": "Stage" - } - }, - "UnderscoreApiStageb34d3ad84e": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "UnderscoreApiDeploymentc6c2bbcee6" - }, - "RestApiId": { - "Ref": "UnderscoreApi" - }, - "StageName": "hoge_fuga" - } - }, - "UnderscoreApi": { - "Type": "AWS::ApiGateway::RestApi", + "HyphenApi": { "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UnderscoreFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HyphenFunction.Arn}/invocations" + } } } } - } - } - } - }, - "UnderscoreFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "UnderscoreApiDeploymentc6c2bbcee6": { - "Type": "AWS::ApiGateway::Deployment", + "HyphenApiDeployment19b8787883": { "Properties": { + "Description": "RestApi deployment id: 19b8787883c74d792cf1ba94de3fd550cf820694", "RestApiId": { - "Ref": "UnderscoreApi" - }, - "Description": "RestApi deployment id: c6c2bbcee65f47628f0f53f9a9e5134f2f6394b5", + "Ref": "HyphenApi" + }, "StageName": "Stage" - } - }, - "HyphenFunctionGetHtmlPermission0c8ecc62cb": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HyphenFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HyphenApi" - } - ] - } - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "HyphenApiStage0c8ecc62cb": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "HyphenApiDeployment19b8787883" - }, + }, "RestApiId": { "Ref": "HyphenApi" - }, + }, "StageName": "hoge-fuga" - } - }, - "UnderscoreFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HyphenFunction": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "UnderscoreFunctionRole", + "HyphenFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "UnderscoreFunctionGetHtmlPermissionb34d3ad84e": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HyphenFunctionGetHtmlPermission0c8ecc62cb": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "UnderscoreFunction" - }, + "Ref": "HyphenFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "UnderscoreApi" + "__ApiId__": "HyphenApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HyphenFunction": { - "Type": "AWS::Lambda::Function", + "HyphenFunctionRole": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HyphenFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HyphenApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "UnderscoreApi": { "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HyphenFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UnderscoreFunction.Arn}/invocations" + } } } } - } + }, + "swagger": "2.0" } - } - }, - "HyphenFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "UnderscoreApiDeploymentc6c2bbcee6": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Description": "RestApi deployment id: c6c2bbcee65f47628f0f53f9a9e5134f2f6394b5", + "RestApiId": { + "Ref": "UnderscoreApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "UnderscoreApiStageb34d3ad84e": { + "Properties": { + "DeploymentId": { + "Ref": "UnderscoreApiDeploymentc6c2bbcee6" + }, + "RestApiId": { + "Ref": "UnderscoreApi" + }, + "StageName": "hoge_fuga" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "UnderscoreFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "UnderscoreFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "UnderscoreFunctionGetHtmlPermissionb34d3ad84e": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "UnderscoreFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "UnderscoreApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "UnderscoreFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_ip_range_blacklist.json b/tests/translator/output/api_with_ip_range_blacklist.json index ae55e78701..80f2eb5ff8 100644 --- a/tests/translator/output/api_with_ip_range_blacklist.json +++ b/tests/translator/output/api_with_ip_range_blacklist.json @@ -1,188 +1,188 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeploymentd123ec976c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: d123ec976c2dab1f9d5da42c13d0960b0c7af65e", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentd123ec976c" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/get": { "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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", + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", - { - "__Stage__": "Prod" - } - ] - } - ], - "Effect": "Allow", + "Action": "execute-api:Invoke", + "Effect": "Allow", "Principal": { "AWS": [ "12345" ] - } - }, - { - "Action": "execute-api:Invoke", + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": "*" - }, + ] + }, { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "IpAddress": { "aws:SourceIp": [ "1.2.3.4" ] } - }, - "Principal": "*" + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/PUT/get", + { + "__Stage__": "Prod" + } + ] + } + ] } - ] + ], + "Version": "2012-10-17" } } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentd123ec976c": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: d123ec976c2dab1f9d5da42c13d0960b0c7af65e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentd123ec976c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_ip_range_whitelist.json b/tests/translator/output/api_with_ip_range_whitelist.json index 3093550ef0..f176e09f70 100644 --- a/tests/translator/output/api_with_ip_range_whitelist.json +++ b/tests/translator/output/api_with_ip_range_whitelist.json @@ -1,191 +1,191 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment864f081ed8" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/get": { "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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", + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": "*" - }, + ] + }, { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { - "NotIpAddress": { + "IpAddress": { "aws:SourceIp": [ "1.2.3.4" ] } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" + ] } - ] + ], + "Version": "2012-10-17" } } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ServerlessRestApiDeployment864f081ed8": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 864f081ed8e2c158aa653c724bfc879fb3f4a78b", "RestApiId": { "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 864f081ed8e2c158aa653c724bfc879fb3f4a78b", + }, "StageName": "Stage" - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment864f081ed8" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_method_aws_iam_auth.json b/tests/translator/output/api_with_method_aws_iam_auth.json index 3b60b06a7f..482ee003d6 100644 --- a/tests/translator/output/api_with_method_aws_iam_auth.json +++ b/tests/translator/output/api_with_method_aws_iam_auth.json @@ -1,7 +1,120 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "put": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/one": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment917ecd4b70": { + "Properties": { + "Description": "RestApi deployment id: 917ecd4b7051b27ff6f3806a8cbfd2d2e8972dee", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment917ecd4b70" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +134,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +146,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +155,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +167,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,10 +176,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +188,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/one", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -114,10 +197,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +209,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/one", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -135,121 +218,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithAwsIamAuthRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - } - }, - "/any/one": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - } - } - } - }, - "MyApiWithoutAuthDeployment917ecd4b70": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 917ecd4b7051b27ff6f3806a8cbfd2d2e8972dee", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment917ecd4b70" - }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_method_settings.json b/tests/translator/output/api_with_method_settings.json index 4f6c874ed3..63c6c9af45 100644 --- a/tests/translator/output/api_with_method_settings.json +++ b/tests/translator/output/api_with_method_settings.json @@ -1,177 +1,177 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "MethodSettings": [ + { + "DataTraceEnabled": true, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": true, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "MethodSettings": [ - { - "HttpMethod": "*", - "MetricsEnabled": true, - "ResourcePath": "/*", - "DataTraceEnabled": true, - "LoggingLevel": "INFO" - } - ], - "RestApiId": { - "Ref": "ExplicitApi" - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "MethodSettings": [ + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "HttpMethod": "*", - "MetricsEnabled": true, - "ResourcePath": "/*", - "DataTraceEnabled": true, - "LoggingLevel": "INFO" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment62b96c1a61" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment62b96c1a61": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", - "StageName": "Stage" - } - }, + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment62b96c1a61": { + "Properties": { + "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62b96c1a61" + }, + "MethodSettings": [ + { + "DataTraceEnabled": true, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": true, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_minimum_compression_size.json b/tests/translator/output/api_with_minimum_compression_size.json index dba3351929..95c2988048 100644 --- a/tests/translator/output/api_with_minimum_compression_size.json +++ b/tests/translator/output/api_with_minimum_compression_size.json @@ -1,161 +1,161 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "MinimumCompressionSize": 256 + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "MinimumCompressionSize": 256, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment62b96c1a61" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment62b96c1a61": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "MinimumCompressionSize": 1024 - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment62b96c1a61": { + "Properties": { + "Description": "RestApi deployment id: 62b96c1a611878eefb13e8ef66dbc71b9ba3dd19", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment62b96c1a61" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_mode.json b/tests/translator/output/api_with_mode.json index 0598e32301..40b1fae371 100644 --- a/tests/translator/output/api_with_mode.json +++ b/tests/translator/output/api_with_mode.json @@ -1,109 +1,109 @@ { "Resources": { - "FunctionRole": { - "Type": "AWS::IAM::Role", + "Api": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "Description": "my description", + "Mode": "overwrite" + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiDeploymentf117c932f7" - }, + }, "RestApiId": { "Ref": "Api" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "Api" + "__ApiId__": "Api", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "Api": { - "Type": "AWS::ApiGateway::RestApi", + "FunctionRole": { "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "my description", - "Mode": "overwrite" - } - }, - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_no_properties.json b/tests/translator/output/api_with_no_properties.json index f609f642ee..292f936ae1 100644 --- a/tests/translator/output/api_with_no_properties.json +++ b/tests/translator/output/api_with_no_properties.json @@ -1,7 +1,54 @@ { "Resources": { + "HTTPApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "HTTPApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "HTTPApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +68,31 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HTTPApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +105,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,74 +117,8 @@ "Value": "SAM" } ] - } - }, - "HtmlFunctionGetHtmlPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": "HTTPApi", - "__Stage__": "*" - } - ] - } - } - }, - "HTTPApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "openapi": "3.0.1", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "payloadFormatVersion": "2.0", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, - "HTTPApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HTTPApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/api_with_open_api_version.json b/tests/translator/output/api_with_open_api_version.json index 406cfeff8f..faf5251a37 100644 --- a/tests/translator/output/api_with_open_api_version.json +++ b/tests/translator/output/api_with_open_api_version.json @@ -1,7 +1,42 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {} + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentd9a0f2ae4f": { + "Properties": { + "Description": "RestApi deployment id: d9a0f2ae4fe2d97b9b91644934a878b6a08cf1c3", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentd9a0f2ae4f" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +56,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +68,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +77,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +89,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,171 +98,165 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {}, - "openapi": "3.0.1" - } - } - }, - "ExplicitApiDeploymentd9a0f2ae4f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: d9a0f2ae4fe2d97b9b91644934a878b6a08cf1c3", - "RestApiId": { - "Ref": "ExplicitApi" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentd9a0f2ae4f" - }, - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } } } - } - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } }, - "responses": {} - }, - "options": { "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } + }, + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + } + }, + "/any": { + "options": { "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } } } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "*" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } } } } - }, - "openapi": "3.0.1" + } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment059bfb64b3": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 059bfb64b3022d253616b67db8dafbf6ae59ae33", "RestApiId": { "Ref": "ServerlessRestApi" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment059bfb64b3" @@ -266,7 +265,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_open_api_version_2.json b/tests/translator/output/api_with_open_api_version_2.json index a9351fbac4..9afcff136b 100644 --- a/tests/translator/output/api_with_open_api_version_2.json +++ b/tests/translator/output/api_with_open_api_version_2.json @@ -1,7 +1,42 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment4154e1c30c": { + "Properties": { + "Description": "RestApi deployment id: 4154e1c30c97469d4946280461125dbfd4324f15", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment4154e1c30c" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +56,10 @@ "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +68,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +77,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +89,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,175 +98,169 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {} - } - } - }, - "ExplicitApiDeployment4154e1c30c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 4154e1c30c97469d4946280461125dbfd4324f15", - "RestApiId": { - "Ref": "ExplicitApi" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment4154e1c30c" + ], + "Version": "2012-10-17" }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } } }, "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" } } } } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentbe85f0cab0": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: be85f0cab0a0d5d60f4b700227b2636ef79a93a8", "RestApiId": { "Ref": "ServerlessRestApi" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentbe85f0cab0" @@ -270,7 +269,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_openapi_definition_body_no_flag.json b/tests/translator/output/api_with_openapi_definition_body_no_flag.json index 2cf200b3b3..b7904447cd 100644 --- a/tests/translator/output/api_with_openapi_definition_body_no_flag.json +++ b/tests/translator/output/api_with_openapi_definition_body_no_flag.json @@ -1,261 +1,261 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeployment9252467a1e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9252467a1edc49ba35cb258640f5e3734cc9fab1", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "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" - } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.1.1", "components": { "securitySchemes": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.1.1", + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "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" + } + } + } + } } - }, + }, "Name": "some api" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentdb4b9da82a" - } - } - }, - "ServerlessRestApiDeploymentdb4b9da82a": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment9252467a1e": { "Properties": { + "Description": "RestApi deployment id: 9252467a1edc49ba35cb258640f5e3734cc9fab1", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: db4b9da82adc6031fcd32bf3a4954485464fc009", + "Ref": "ExplicitApi" + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment9252467a1e" + }, "RestApiId": { "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", + }, + "StageName": "SomeStage", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment9252467a1e" } - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 } - }, + }, "Schema": [ { - "AttributeDataType": "String", - "Required": false, - "Name": "email" + "AttributeDataType": "String", + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, + }, + "Type": "AWS::Cognito::UserPool" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "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": {}, "security": [ { "MyCognitoAuth": [] } - ], - "responses": {} + ], + "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" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, + }, + "swagger": "2.0" + }, "Name": "some api" - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentdb4b9da82a": { + "Properties": { + "Description": "RestApi deployment id: db4b9da82adc6031fcd32bf3a4954485464fc009", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentdb4b9da82a" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/api_with_path_parameters.json b/tests/translator/output/api_with_path_parameters.json index f66da7a716..ae13b17323 100644 --- a/tests/translator/output/api_with_path_parameters.json +++ b/tests/translator/output/api_with_path_parameters.json @@ -1,7 +1,37 @@ { "Resources": { + "HtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +51,10 @@ "Value": "SAM" } ] - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "HtmlFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -70,10 +70,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -89,38 +89,38 @@ } ] } - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "HtmlFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "HtmlApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_resource_policy.json b/tests/translator/output/api_with_resource_policy.json index f99868645e..e89aab76ee 100644 --- a/tests/translator/output/api_with_resource_policy.json +++ b/tests/translator/output/api_with_resource_policy.json @@ -1,7 +1,89 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/one": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/three": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/two": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + "Version": "2012-10-17" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment8bc819edf7": { + "Properties": { + "Description": "RestApi deployment id: 8bc819edf722dc6b9e6ab0811488a94683dd79d1", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +103,10 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "ExplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,10 +124,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "ExplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -93,10 +145,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPutHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +157,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", { "__ApiId__": { "Ref": "ExplicitApi" @@ -114,10 +166,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPutHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +178,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", { "__ApiId__": { "Ref": "ExplicitApi" @@ -135,93 +187,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ExplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - } - } - } - } - }, - "ExplicitApiDeployment8bc819edf7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 8bc819edf722dc6b9e6ab0811488a94683dd79d1", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment8bc819edf7" @@ -230,7 +229,8 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_resource_policy_global.json b/tests/translator/output/api_with_resource_policy_global.json index 15b8d99106..dceb455770 100644 --- a/tests/translator/output/api_with_resource_policy_global.json +++ b/tests/translator/output/api_with_resource_policy_global.json @@ -2,231 +2,231 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { "StageName": { - "Default": "MyOwnStage", + "Default": "MyOwnStage", "Type": "String" } - }, + }, "Resources": { "AnotherApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0", + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { "Fn::If": [ - "C1", + "C1", { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*/*/*" ] - }, + }, { - "Action": "execute-api:Another", + "Action": "execute-api:Another", "Resource": [ "execute-api:/*/*/*" ] } ] - } + }, + "Version": "2012-10-17" } } - } - }, - "ExplicitApiDeploymenta5a5c4e3ff": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "AnotherApiDeploymentfdf1387e0a": { "Properties": { + "Description": "RestApi deployment id: fdf1387e0a89fa15996401a79284cdaaf2c43844", "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a5a5c4e3ff6901cf27436628359ed20300d34aa4", + "Ref": "AnotherApi" + }, "StageName": "Stage" - } - }, - "ExplicitApiStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "AnotherApiStage": { "Properties": { "DeploymentId": { - "Ref": "ExplicitApiDeploymenta5a5c4e3ff" - }, + "Ref": "AnotherApiDeploymentfdf1387e0a" + }, "RestApiId": { - "Ref": "ExplicitApi" - }, + "Ref": "AnotherApi" + }, "StageName": { "Ref": "StageName" } - } - }, - "ExplicitApiFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ExplicitApi": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ExplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ExplicitApi" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } } } - ] + }, + "swagger": 2.0, + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + }, + { + "Fn::If": [ + "C1", + { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + { + "Action": "execute-api:Blah", + "Resource": [ + "execute-api:/*/*/*" + ] + } + ] + } + ], + "Version": "2012-10-17" + } } - } - }, - "AnotherApiDeploymentfdf1387e0a": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta5a5c4e3ff": { "Properties": { + "Description": "RestApi deployment id: a5a5c4e3ff6901cf27436628359ed20300d34aa4", "RestApiId": { - "Ref": "AnotherApi" - }, - "Description": "RestApi deployment id: fdf1387e0a89fa15996401a79284cdaaf2c43844", + "Ref": "ExplicitApi" + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ExplicitApiFunctionRole", + "ExplicitApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "ExplicitApiFunctionGetHtmlPermissionStage": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ExplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "AnotherApiStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::IAM::Role" + }, + "ExplicitApiStage": { "Properties": { "DeploymentId": { - "Ref": "AnotherApiDeploymentfdf1387e0a" - }, + "Ref": "ExplicitApiDeploymenta5a5c4e3ff" + }, "RestApiId": { - "Ref": "AnotherApi" - }, + "Ref": "ExplicitApi" + }, "StageName": { "Ref": "StageName" } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": 2.0, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sts:AssumeRole", - "Effect": "Allow", - "Principal": { - "Service": "lambda.amazonaws.com" - } - }, - { - "Fn::If": [ - "C1", - { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - }, - { - "Action": "execute-api:Blah", - "Resource": [ - "execute-api:/*/*/*" - ] - } - ] - } - ] - } - } - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_resource_policy_global_implicit.json b/tests/translator/output/api_with_resource_policy_global_implicit.json index 6a191b414d..3d67bf0dfd 100644 --- a/tests/translator/output/api_with_resource_policy_global_implicit.json +++ b/tests/translator/output/api_with_resource_policy_global_implicit.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MinimalFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MinimalFunctionAddItemAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/add", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MinimalFunctionAddItemAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MinimalFunctionAddItemPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/add", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,47 +62,76 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MinimalFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/any/add": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MinimalFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { "Action": "execute-api:Invoke", @@ -147,23 +145,24 @@ "execute-api:/*/*/*" ] } - ] + ], + "Version": "2012-10-17" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment7195c7fb8d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 7195c7fb8d4c3b983caf56419db67bec5249cfa6", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment7195c7fb8d" @@ -172,7 +171,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_resource_refs.json b/tests/translator/output/api_with_resource_refs.json index e32db402a5..682a5522d7 100644 --- a/tests/translator/output/api_with_resource_refs.json +++ b/tests/translator/output/api_with_resource_refs.json @@ -1,7 +1,59 @@ { + "Outputs": { + "ExplicitApiDeployment": { + "Value": { + "Ref": "MyApiDeployment359f256a3b" + } + }, + "ExplicitApiStage": { + "Value": { + "Ref": "MyApifooStage" + } + }, + "ImplicitApiDeployment": { + "Value": { + "Ref": "ServerlessRestApiDeployment84667018a8" + } + }, + "ImplicitApiStage": { + "Value": { + "Ref": "ServerlessRestApiProdStage" + } + } + }, "Resources": { + "MyApi": { + "Properties": { + "Body": { + "a": "swagger", + "this": "is" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment359f256a3b": { + "Properties": { + "Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApifooStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment359f256a3b" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "foo" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +73,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionGetHtmlAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,10 +94,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -93,91 +115,90 @@ } ] } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "swagger" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment359f256a3b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyApifooStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment359f256a3b" - }, - "RestApiId": { - "Ref": "MyApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "foo" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/html": { - "get": { + "/any/html": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/html": { - "x-amazon-apigateway-any-method": { + "/html": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "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" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment84667018a8": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 84667018a87e0a0cfdf5df74340e57e8ffaf7ce5", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment84667018a8" @@ -186,29 +207,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } - } - }, - "Outputs": { - "ImplicitApiDeployment": { - "Value": { - "Ref": "ServerlessRestApiDeployment84667018a8" - } - }, - "ImplicitApiStage": { - "Value": { - "Ref": "ServerlessRestApiProdStage" - } - }, - "ExplicitApiDeployment": { - "Value": { - "Ref": "MyApiDeployment359f256a3b" - } - }, - "ExplicitApiStage": { - "Value": { - "Ref": "MyApifooStage" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_security_definition_and_components.json b/tests/translator/output/api_with_security_definition_and_components.json index d6cf670858..ecae49649e 100644 --- a/tests/translator/output/api_with_security_definition_and_components.json +++ b/tests/translator/output/api_with_security_definition_and_components.json @@ -1,7 +1,82 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "schemas": { + "Error": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "Object" + } + }, + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment195f5bf5d0": { + "Properties": { + "Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment195f5bf5d0" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +96,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +114,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,83 +126,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiDeployment195f5bf5d0": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment195f5bf5d0" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - }, - "schemas": { - "Error": { - "type": "Object", - "properties": { - "message": { - "type": "string" - } - } - } - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_security_definition_and_no_components.json b/tests/translator/output/api_with_security_definition_and_no_components.json index 69c13968b8..9b64de0930 100644 --- a/tests/translator/output/api_with_security_definition_and_no_components.json +++ b/tests/translator/output/api_with_security_definition_and_no_components.json @@ -1,7 +1,72 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment407993a935": { + "Properties": { + "Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment407993a935" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +86,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +104,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,73 +116,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment407993a935" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment407993a935": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_security_definition_and_none_components.json b/tests/translator/output/api_with_security_definition_and_none_components.json index 236ec8c47c..2f4fd99c67 100644 --- a/tests/translator/output/api_with_security_definition_and_none_components.json +++ b/tests/translator/output/api_with_security_definition_and_none_components.json @@ -1,7 +1,72 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment61b3921bb7": { + "Properties": { + "Description": "RestApi deployment id: 61b3921bb7522c20a8e0de1d24c974267f3ec17b", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment61b3921bb7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +86,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +104,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,73 +116,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment61b3921bb7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment61b3921bb7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 61b3921bb7522c20a8e0de1d24c974267f3ec17b", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - } - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_source_vpc_blacklist.json b/tests/translator/output/api_with_source_vpc_blacklist.json index 0608fe5774..2e7f628309 100644 --- a/tests/translator/output/api_with_source_vpc_blacklist.json +++ b/tests/translator/output/api_with_source_vpc_blacklist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionApiAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,81 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any/get": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/get": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "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", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -146,12 +145,19 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Condition": { + "StringEquals": { + "aws:SourceVpce": [ + "vpce-3456" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -161,19 +167,12 @@ } ] } - ], - "Principal": "*", - "Condition": { - "StringEquals": { - "aws:SourceVpce": [ - "vpce-3456" - ] - } - } + ] }, { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -183,12 +182,19 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Condition": { + "StringEquals": { + "aws:SourceVpce": [ + "vpce-3456" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -198,33 +204,26 @@ } ] } - ], - "Principal": "*", - "Condition": { - "StringEquals": { - "aws:SourceVpce": [ - "vpce-3456" - ] - } - } + ] } - ] + ], + "Version": "2012-10-17" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment4add408372": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 4add4083725c01f871dba289c1db5c8876994311", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment4add408372" @@ -233,7 +232,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_source_vpc_whitelist.json b/tests/translator/output/api_with_source_vpc_whitelist.json index 8b452ffcfa..872932ad19 100644 --- a/tests/translator/output/api_with_source_vpc_whitelist.json +++ b/tests/translator/output/api_with_source_vpc_whitelist.json @@ -1,13 +1,49 @@ { "Parameters": { "Vpc1": { - "Type": "String", - "Default": "vpc-1234" + "Default": "vpc-1234", + "Type": "String" } }, "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment5332c373d4": { + "Properties": { + "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment5332c373d4" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -26,40 +62,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionFetchAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionApiAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -68,7 +74,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/fetch", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/get", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -77,10 +83,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionApiAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionApiPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -89,7 +95,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/get", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -98,10 +104,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionFetchAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -110,7 +116,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/fetch", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -119,10 +125,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionFetchPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -131,7 +137,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -140,112 +146,105 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {} - } - } - }, - "MyApiDeployment5332c373d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", - "RestApiId": { - "Ref": "MyApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment5332c373d4" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any/fetch": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/any/get": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/fetch": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/fetch": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "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", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -255,23 +254,10 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", - { - "__Stage__": "Prod" - } - ] - } - ], - "Principal": "*", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -279,26 +265,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/*/any/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -308,8 +292,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -317,26 +303,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/fetch", + "execute-api:/${__Stage__}/*/any/get", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -346,8 +330,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -355,26 +341,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/*/any/fetch", + "execute-api:/${__Stage__}/POST/fetch", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -384,8 +368,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -393,25 +379,38 @@ "vpc-5678" ] } - } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/*/any/fetch", + { + "__Stage__": "Prod" + } + ] + } + ] } - ] + ], + "Version": "2012-10-17" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymente76e291d74": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: e76e291d74b93709a6c6093ca05608700bb61fa6", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymente76e291d74" @@ -420,7 +419,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_stage_tags.json b/tests/translator/output/api_with_stage_tags.json index 702a6b1815..e31a2c08b3 100644 --- a/tests/translator/output/api_with_stage_tags.json +++ b/tests/translator/output/api_with_stage_tags.json @@ -1,67 +1,67 @@ { "Parameters": { "TagValueParam": { - "Default": "value", + "Default": "value", "Type": "String" } - }, + }, "Resources": { - "MyApiWithStageTagsDeployment5332c373d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithStageTags" - }, - "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", - "StageName": "Stage" - } - }, "MyApiWithStageTags": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, + }, + "version": "1.0" + }, + "paths": {}, "swagger": "2.0" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithStageTagsDeployment5332c373d4": { + "Properties": { + "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", + "RestApiId": { + "Ref": "MyApiWithStageTags" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiWithStageTagsProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithStageTagsDeployment5332c373d4" - }, + }, "RestApiId": { "Ref": "MyApiWithStageTags" - }, - "StageName": "Prod", + }, + "StageName": "Prod", "Tags": [ { - "Value": "TagValue1", - "Key": "TagKey1" - }, + "Key": "TagKey1", + "Value": "TagValue1" + }, { - "Value": "", - "Key": "TagKey2" - }, + "Key": "TagKey2", + "Value": "" + }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" - }, + } + }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ] - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_swagger_and_openapi_with_auth.json b/tests/translator/output/api_with_swagger_and_openapi_with_auth.json index 3e6de658ba..d215e100d3 100644 --- a/tests/translator/output/api_with_swagger_and_openapi_with_auth.json +++ b/tests/translator/output/api_with_swagger_and_openapi_with_auth.json @@ -1,28 +1,87 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", + "ExplicitApi": { "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.1.1", + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "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" + } + } + } + } + }, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + }, + "swagger": 2.0 }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } + "Name": "some api" + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment7c4f7dda23": { + "Properties": { + "Description": "RestApi deployment id: 7c4f7dda23acd71e4a653861510d82ad7809e562", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiSomeStageStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment7c4f7dda23" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -42,40 +101,10 @@ "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +113,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,10 +122,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionGetHtmlAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +134,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -114,144 +143,111 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "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": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyCognitoAuth": [] - } - ] - } - } - }, - "securityDefinitions": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - { - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - } + ], + "Version": "2012-10-17" }, - "Name": "some api" - } - }, - "ExplicitApiDeployment7c4f7dda23": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7c4f7dda23acd71e4a653861510d82ad7809e562", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", + "MyUserPool": { "Properties": { - "CacheClusterEnabled": true, - "CacheClusterSize": "1.6", - "DeploymentId": { - "Ref": "ExplicitApiDeployment7c4f7dda23" - }, - "RestApiId": { - "Ref": "ExplicitApi" + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } }, - "StageName": "SomeStage", - "Variables": { - "SomeVar": "Value" - } - } + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, + } + } + }, + "/any": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "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" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -259,26 +255,29 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" }, "Name": "some api" - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymente091b9b9a0": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: e091b9b9a0d7b8b9db6fee8c4ad295eb98edde08", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "CacheClusterEnabled": true, "CacheClusterSize": "1.6", @@ -292,7 +291,8 @@ "Variables": { "SomeVar": "Value" } - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_swagger_authorizer_none.json b/tests/translator/output/api_with_swagger_authorizer_none.json index ba153a1315..e6836b7bc1 100644 --- a/tests/translator/output/api_with_swagger_authorizer_none.json +++ b/tests/translator/output/api_with_swagger_authorizer_none.json @@ -1,311 +1,56 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "/any/cognito": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "NONE": [] } - ] - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { "responses": {}, "security": [ { "NONE": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -313,25 +58,28 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeploymentbbb7da3922": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: bbb7da3922ad233fdb9e35bda022b508620330e7", "RestApiId": { "Ref": "MyApiWithCognitoAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeploymentbbb7da3922" @@ -340,63 +88,167 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { + "/lambda-request": { "get": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "passthroughBehavior": "when_no_match", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } + } + } + } + }, + "schemes": [ + "https" + ], + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": 2.0 + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeployment6c7d4d239e": { + "Properties": { + "Description": "RestApi deployment id: 6c7d4d239ebc281207f7684b2b51eb16610d88fc", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment6c7d4d239e" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "NONE": [] } - ] - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-token": { + "get": { "responses": {}, "security": [ { "NONE": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -409,164 +261,312 @@ } } ] - } + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaTokenAuthDeploymentfc08a5662f": { + "Properties": { + "Description": "RestApi deployment id: fc08a5662f8d2ea42fa3ba34ec4bade80bfb144b", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" } } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeploymentfc08a5662f" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthDeploymentfc08a5662f": { - "Type": "AWS::ApiGateway::Deployment", + "MyAuthFnRole": { "Properties": { - "Description": "RestApi deployment id: fc08a5662f8d2ea42fa3ba34ec4bade80bfb144b", - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFn": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeploymentfc08a5662f" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs8.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnCognitoPermissionProd": { "Properties": { - "Body": { - "swagger": 2.0, - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "schemes": [ - "https" - ], - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - }, - "passthroughBehavior": "when_no_match" - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - } - }, - "securityDefinitions": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } - } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeployment6c7d4d239e": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 6c7d4d239ebc281207f7684b2b51eb16610d88fc", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment6c7d4d239e" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_usageplans.json b/tests/translator/output/api_with_usageplans.json index 9fd2ac1535..d38aab365d 100644 --- a/tests/translator/output/api_with_usageplans.json +++ b/tests/translator/output/api_with_usageplans.json @@ -1,59 +1,342 @@ { + "Outputs": { + "ApiKey": { + "Description": "Api Key", + "Value": { + "Ref": "ServerlessApiKey" + } + }, + "ApiOneUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "ApiThreeUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "ApiTwoUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "UsagePlan": { + "Description": "Usage Plan physical Id", + "Value": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "UsagePlanKey": { + "Description": "Usage Plan Key", + "Value": { + "Ref": "MyApiTwoUsagePlanKey" + } + } + }, "Resources": { - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", + "MyApiOne": { "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any/path/one": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + }, + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiOneDeploymente137b7d111": { + "Properties": { + "Description": "RestApi deployment id: e137b7d11103c574a56f89fda57c1929002da60a", + "RestApiId": { + "Ref": "MyApiOne" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeploymente137b7d111" }, - "Runtime": "nodejs12.x", - "Tags": [ + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiThree": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/three": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiThreeDeployment1d9cff47dc": { + "Properties": { + "Description": "RestApi deployment id: 1d9cff47dc9b822750c668c73b4534022483de6d", + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiThreeDeployment1d9cff47dc" + }, + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoApiKey": { + "DependsOn": [ + "MyApiTwoUsagePlan" + ], + "Properties": { + "Enabled": true, + "StageKeys": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": { + "Ref": "MyApiTwoProdStage" + } } ] - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyApiTwoDeploymente9d97923b9": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiTwoProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeploymente9d97923b9" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwoUsagePlan": { + "DependsOn": [ + "MyApiTwo" + ], + "Properties": { + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiTwo" + }, + "Stage": { + "Ref": "MyApiTwoProdStage" } + } + ], + "Description": "Description for usage plan", + "Quota": { + "Limit": 10, + "Offset": 10, + "Period": "MONTH" + }, + "Tags": [ + { + "Key": "key1", + "Value": "value1" + }, + { + "Key": "key2", + "Value": "value2" + } + ], + "Throttle": { + "BurstLimit": 1000, + "RateLimit": 1000 + }, + "UsagePlanName": "SomeRandomName" + }, + "Type": "AWS::ApiGateway::UsagePlan" + }, + "MyApiTwoUsagePlanKey": { + "DependsOn": [ + "MyApiTwoApiKey" + ], + "Properties": { + "KeyId": { + "Ref": "MyApiTwoApiKey" + }, + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" + }, + "MyFunctionOne": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionOneApiKeyAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +354,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,35 +375,12 @@ } ] } - } - }, - "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionTwoRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionOneRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -133,7 +393,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -144,52 +405,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionTwoImplicitApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/event", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", - { - "__ApiId__": { - "Ref": "MyApiTwo" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionThree": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -208,13 +427,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionThreeApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionThree" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + { + "__ApiId__": { + "Ref": "MyApiThree" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionThreeRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -227,7 +466,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -238,307 +478,193 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionThreeApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionTwo": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionTwoRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionTwoApiKeyPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionThree" + "Ref": "MyFunctionTwo" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { "__ApiId__": { - "Ref": "MyApiThree" + "Ref": "MyApiTwo" }, "__Stage__": "*" } ] } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/path/one": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiOneDeploymente137b7d111": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: e137b7d11103c574a56f89fda57c1929002da60a", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeploymente137b7d111" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiTwoDeploymente9d97923b9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeploymente9d97923b9" - }, - "RestApiId": { - "Ref": "MyApiTwo" + "MyFunctionTwoImplicitApiEventPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/event", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiTwoUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", - "DependsOn": [ - "MyApiTwo" - ], + "MyFunctionTwoRole": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiTwo" - }, - "Stage": { - "Ref": "MyApiTwoProdStage" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - } - ], - "Description": "Description for usage plan", - "Quota": { - "Limit": 10, - "Offset": 10, - "Period": "MONTH" + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Key": "key1", - "Value": "value1" - }, - { - "Key": "key2", - "Value": "value2" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Throttle": { - "BurstLimit": 1000, - "RateLimit": 1000 - }, - "UsagePlanName": "SomeRandomName" - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiTwoApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "ServerlessApiKey": { "DependsOn": [ - "MyApiTwoUsagePlan" + "ServerlessUsagePlan" ], "Properties": { "Enabled": true, "StageKeys": [ { "RestApiId": { - "Ref": "MyApiTwo" + "Ref": "MyApiThree" }, "StageName": { - "Ref": "MyApiTwoProdStage" + "Ref": "MyApiThreeProdStage" + } + }, + { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": { + "Ref": "ServerlessRestApiProdStage" } } ] - } - }, - "MyApiTwoUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "DependsOn": [ - "MyApiTwoApiKey" - ], - "Properties": { - "KeyId": { - "Ref": "MyApiTwoApiKey" - }, - "KeyType": "API_KEY", - "UsagePlanId": { - "Ref": "MyApiTwoUsagePlan" - } - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiThree": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/path/three": { + "/path/event": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" - } - }, "responses": {}, "security": [ { "api_key": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } } } }, "securityDefinitions": { "api_key": { - "type": "apiKey", + "in": "header", "name": "x-api-key", - "in": "header" + "type": "apiKey" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiThreeDeployment1d9cff47dc": { - "Type": "AWS::ApiGateway::Deployment", + "ServerlessRestApiDeployment7a26848ac9": { "Properties": { - "Description": "RestApi deployment id: 1d9cff47dc9b822750c668c73b4534022483de6d", + "Description": "RestApi deployment id: 7a26848ac97d678aaf266a8a883d0abd463b3bbc", "RestApiId": { - "Ref": "MyApiThree" + "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ServerlessRestApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiThreeDeployment1d9cff47dc" + "Ref": "ServerlessRestApiDeployment7a26848ac9" }, "RestApiId": { - "Ref": "MyApiThree" + "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", "DependsOn": [ "MyApiThree", "ServerlessRestApi" @@ -562,37 +688,10 @@ } } ] - } - }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "DependsOn": [ - "ServerlessUsagePlan" - ], - "Properties": { - "Enabled": true, - "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": { - "Ref": "MyApiThreeProdStage" - } - }, - { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": { - "Ref": "ServerlessRestApiProdStage" - } - } - ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "DependsOn": [ "ServerlessApiKey" ], @@ -604,107 +703,8 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/event": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "ServerlessRestApiDeployment7a26848ac9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7a26848ac97d678aaf266a8a883d0abd463b3bbc", - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment7a26848ac9" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - } - }, - "Outputs": { - "ApiOneUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "ApiTwoUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "ApiThreeUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "UsagePlan": { - "Description": "Usage Plan physical Id", - "Value": { - "Ref": "MyApiTwoUsagePlan" - } - }, - "UsagePlanKey": { - "Description": "Usage Plan Key", - "Value": { - "Ref": "MyApiTwoUsagePlanKey" - } - }, - "ApiKey": { - "Description": "Api Key", - "Value": { - "Ref": "ServerlessApiKey" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_usageplans_intrinsics.json b/tests/translator/output/api_with_usageplans_intrinsics.json index ce2e5413df..efafb2df8f 100644 --- a/tests/translator/output/api_with_usageplans_intrinsics.json +++ b/tests/translator/output/api_with_usageplans_intrinsics.json @@ -1,26 +1,26 @@ { + "Conditions": { + "C1": { + "Fn::Equals": [ + true, + true + ] + } + }, "Outputs": { - "ApiTwoUrl": { + "ApiOneUrl": { "Description": "API endpoint URL for Prod environment", "Value": { - "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } }, - "ApiOneUrl": { + "ApiTwoUrl": { "Description": "API endpoint URL for Prod environment", "Value": { - "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } } }, - "Conditions": { - "C1": { - "Fn::Equals": [ - true, - true - ] - } - }, "Parameters": { "UsagePlanType": { "Default": "PER_API", @@ -28,32 +28,97 @@ } }, "Resources": { - "MyApiTwoUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "MyApiOne": { + "Condition": "C1", "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "MyApiTwoApiKey" - }, - "UsagePlanId": { - "Ref": "MyApiTwoUsagePlan" + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + } } }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiOneApiKey": { + "Condition": "C1", "DependsOn": [ - "MyApiTwoApiKey" - ] + "MyApiOneUsagePlan" + ], + "Properties": { + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": { + "Ref": "MyApiOneProdStage" + } + } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiTwoDeploymenta78b9db9dd": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiOneDeployment37a3a51a0f": { + "Condition": "C1", "Properties": { + "Description": "RestApi deployment id: 37a3a51a0fd9d750b0bd43bdab40046fdc167e8d", "RestApiId": { - "Ref": "MyApiTwo" + "Ref": "MyApiOne" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment37a3a51a0f" }, - "Description": "RestApi deployment id: a78b9db9ddd80dec31c4b3c3e2b6e037345252ce" - } + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApiOneUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "Condition": "C1", + "DependsOn": [ + "MyApiOne" + ], "Properties": { "ApiStages": [ { @@ -66,177 +131,218 @@ } ] }, + "Type": "AWS::ApiGateway::UsagePlan" + }, + "MyApiOneUsagePlanKey": { + "Condition": "C1", "DependsOn": [ - "MyApiOne" + "MyApiOneApiKey" ], - "Condition": "C1" + "Properties": { + "KeyId": { + "Ref": "MyApiOneApiKey" + }, + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "MyApiOneUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" }, - "MyApiTwoUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiTwo": { "Properties": { - "ApiStages": [ + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoApiKey": { + "DependsOn": [ + "MyApiTwoUsagePlan" + ], + "Properties": { + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } } ] }, - "DependsOn": [ - "MyApiTwo" - ] + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiTwoDeploymenta78b9db9dd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeploymenta78b9db9dd" - }, + "Description": "RestApi deployment id: a78b9db9ddd80dec31c4b3c3e2b6e037345252ce", "RestApiId": { "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } - }, - "MyApiOneDeployment37a3a51a0f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiOne" - }, - "Description": "RestApi deployment id: 37a3a51a0fd9d750b0bd43bdab40046fdc167e8d" + } }, - "Condition": "C1" + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiTwoProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiOneDeployment37a3a51a0f" + "Ref": "MyApiTwoDeploymenta78b9db9dd" }, "RestApiId": { - "Ref": "MyApiOne" + "Ref": "MyApiTwo" }, "StageName": "Prod" }, - "Condition": "C1" + "Type": "AWS::ApiGateway::Stage" }, - "MyApiOneApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyApiTwoUsagePlan": { + "DependsOn": [ + "MyApiTwo" + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { - "Ref": "MyApiOne" + "ApiId": { + "Ref": "MyApiTwo" }, - "StageName": { - "Ref": "MyApiOneProdStage" + "Stage": { + "Ref": "MyApiTwoProdStage" } } ] }, + "Type": "AWS::ApiGateway::UsagePlan" + }, + "MyApiTwoUsagePlanKey": { "DependsOn": [ - "MyApiOneUsagePlan" + "MyApiTwoApiKey" ], - "Condition": "C1" - }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiOneUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "Properties": { - "KeyType": "API_KEY", "KeyId": { - "Ref": "MyApiOneApiKey" + "Ref": "MyApiTwoApiKey" }, + "KeyType": "API_KEY", "UsagePlanId": { - "Ref": "MyApiOneUsagePlan" + "Ref": "MyApiTwoUsagePlan" } }, - "DependsOn": [ - "MyApiOneApiKey" - ], - "Condition": "C1" + "Type": "AWS::ApiGateway::UsagePlanKey" }, - "MyApiTwoApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyFunctionOne": { "Properties": { - "Enabled": true, - "StageKeys": [ + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": { - "Ref": "MyApiTwoProdStage" - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyApiTwoUsagePlan" - ] + "Type": "AWS::Lambda::Function" }, "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionOne" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiOne" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionTwoRole", @@ -246,41 +352,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionTwo" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiTwo" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -293,122 +395,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } }, - "Condition": "C1" - }, - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_usageplans_shared_attributes_three.json b/tests/translator/output/api_with_usageplans_shared_attributes_three.json index 7d6b336e1c..8ebfe67412 100644 --- a/tests/translator/output/api_with_usageplans_shared_attributes_three.json +++ b/tests/translator/output/api_with_usageplans_shared_attributes_three.json @@ -14,8 +14,205 @@ } }, "Resources": { + "MyApiOne": { + "Condition": "C1", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Delete" + }, + "MyApiOneDeployment46fb22a429": { + "Condition": "C1", + "Properties": { + "Description": "RestApi deployment id: 46fb22a42926db6f64e09966936d074ec6bb9392", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Delete" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment46fb22a429" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Delete" + }, + "MyApiThree": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/three": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiThreeDeployment1d9cff47dc": { + "Properties": { + "Description": "RestApi deployment id: 1d9cff47dc9b822750c668c73b4534022483de6d", + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiThreeDeployment1d9cff47dc" + }, + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Condition": "C2", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Snapshot" + }, + "MyApiTwoDeploymente9d97923b9": { + "Condition": "C2", + "Properties": { + "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Snapshot" + }, + "MyApiTwoProdStage": { + "Condition": "C2", + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeploymente9d97923b9" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Snapshot" + }, "MyFunctionOne": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -34,13 +231,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -53,7 +270,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -64,31 +282,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", + "MyFunctionThree": { "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -96,7 +293,7 @@ "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionTwoRole", + "MyFunctionThreeRole", "Arn" ] }, @@ -107,13 +304,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionThreeApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionThree" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + { + "__ApiId__": { + "Ref": "MyApiThree" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionThreeRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -126,7 +343,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -137,10 +355,32 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionTwo": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionTwoRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -158,35 +398,12 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionThree": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionThreeRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionThreeRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -199,7 +416,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -210,176 +428,86 @@ "Value": "SAM" } ] - } - }, - "MyFunctionThreeApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionThree" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", - { - "__ApiId__": { - "Ref": "MyApiThree" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiOneDeployment46fb22a429": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "Description": "RestApi deployment id: 46fb22a42926db6f64e09966936d074ec6bb9392", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment46fb22a429" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::IAM::Role" }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "ServerlessApiKey": { "DependsOn": [ - "MyApiOne", - "MyApiTwo", - "MyApiThree" + "ServerlessUsagePlan" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiThree" }, - "Stage": { + "StageName": { "Ref": "MyApiThreeProdStage" } } ] - } - }, - "ServerlessApiKey": { + }, "Type": "AWS::ApiGateway::ApiKey", + "UpdateReplacePolicy": "Snapshot" + }, + "ServerlessUsagePlan": { "DependsOn": [ - "ServerlessUsagePlan" + "MyApiOne", + "MyApiTwo", + "MyApiThree" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiOne" }, - "StageName": { + "Stage": { "Ref": "MyApiOneProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiThree" }, - "StageName": { + "Stage": { "Ref": "MyApiThreeProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan", + "UpdateReplacePolicy": "Snapshot" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "DependsOn": [ "ServerlessApiKey" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { "KeyId": { "Ref": "ServerlessApiKey" @@ -388,137 +516,9 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiTwoDeploymente9d97923b9": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeploymente9d97923b9" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } - }, - "MyApiThree": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/three": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiThreeDeployment1d9cff47dc": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 1d9cff47dc9b822750c668c73b4534022483de6d", - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": "Stage" - } - }, - "MyApiThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiThreeDeployment1d9cff47dc" - }, - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey", + "UpdateReplacePolicy": "Snapshot" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_usageplans_shared_attributes_two.json b/tests/translator/output/api_with_usageplans_shared_attributes_two.json index 3412bb0415..50cd9feca6 100644 --- a/tests/translator/output/api_with_usageplans_shared_attributes_two.json +++ b/tests/translator/output/api_with_usageplans_shared_attributes_two.json @@ -24,8 +24,143 @@ } }, "Resources": { + "MyApiOne": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiOneDeployment46fb22a429": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "Description": "RestApi deployment id: 46fb22a42926db6f64e09966936d074ec6bb9392", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment46fb22a429" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoDeploymente9d97923b9": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiTwoProdStage": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeploymente9d97923b9" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionOne": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -44,13 +179,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -63,7 +218,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -74,31 +230,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -117,13 +252,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionTwoApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + { + "__ApiId__": { + "Ref": "MyApiTwo" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -136,7 +291,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -147,162 +303,73 @@ "Value": "SAM" } ] - } - }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", - { - "__ApiId__": { - "Ref": "MyApiTwo" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "DeletionPolicy": "Delete", - "Condition": "C1", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiOneDeployment46fb22a429": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C1", - "DeletionPolicy": "Delete", - "Properties": { - "Description": "RestApi deployment id: 46fb22a42926db6f64e09966936d074ec6bb9392", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C1", - "DeletionPolicy": "Delete", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment46fb22a429" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", - "DependsOn": [ - "MyApiOne", - "MyApiTwo" - ], + "ServerlessApiKey": { "Condition": "SharedUsagePlanCondition", "DeletionPolicy": "Retain", + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "DependsOn": [ - "ServerlessUsagePlan" - ], + "ServerlessUsagePlan": { "Condition": "SharedUsagePlanCondition", "DeletionPolicy": "Retain", + "DependsOn": [ + "MyApiOne", + "MyApiTwo" + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiOne" }, - "StageName": { + "Stage": { "Ref": "MyApiOneProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "Condition": "SharedUsagePlanCondition", + "DeletionPolicy": "Retain", "DependsOn": [ "ServerlessApiKey" ], - "Condition": "SharedUsagePlanCondition", - "DeletionPolicy": "Retain", "Properties": { "KeyId": { "Ref": "ServerlessApiKey" @@ -311,75 +378,8 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "DeletionPolicy": "Retain", - "Condition": "C2", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - } - }, - "MyApiTwoDeploymente9d97923b9": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C2", - "DeletionPolicy": "Retain", - "Properties": { - "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C2", - "DeletionPolicy": "Retain", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeploymente9d97923b9" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_usageplans_shared_no_side_effect_1.json b/tests/translator/output/api_with_usageplans_shared_no_side_effect_1.json index c54e7afab6..2ba0408327 100644 --- a/tests/translator/output/api_with_usageplans_shared_no_side_effect_1.json +++ b/tests/translator/output/api_with_usageplans_shared_no_side_effect_1.json @@ -1,61 +1,118 @@ { "Resources": { - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiOne": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiOne" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "Stage": { - "Ref": "MyApiOneProdStage" + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } } }, - { - "ApiId": { - "Ref": "MyApiTwo" - }, - "Stage": { - "Ref": "MyApiTwoProdStage" + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - ] + }, + "swagger": "2.0" + } }, - "DependsOn": [ - "MyApiOne", - "MyApiTwo" - ] + "Type": "AWS::ApiGateway::RestApi" }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyApiOneDeployment46fb22a429": { "Properties": { - "Enabled": true, - "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiOne" + "Description": "RestApi deployment id: 46fb22a42926db6f64e09966936d074ec6bb9392", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment46fb22a429" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "StageName": { - "Ref": "MyApiOneProdStage" + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } } }, - { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": { - "Ref": "MyApiTwoProdStage" + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - ] + }, + "swagger": "2.0" + } }, - "DependsOn": [ - "ServerlessUsagePlan" - ] + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoDeploymente9d97923b9": { + "Properties": { + "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiTwoDeploymente9d97923b9" @@ -64,40 +121,55 @@ "Ref": "MyApiTwo" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "MyFunctionOne": { "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "ServerlessApiKey" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "UsagePlanId": { - "Ref": "ServerlessUsagePlan" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "DependsOn": [ - "ServerlessApiKey" - ] + "Type": "AWS::Lambda::Function" }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionOneApiKeyPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment46fb22a429" - }, - "RestApiId": { - "Ref": "MyApiOne" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionOneRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -110,36 +182,27 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiTwoDeploymente9d97923b9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "Description": "RestApi deployment id: e9d97923b94d0801cd85a8970b3c3f84aa274003", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionTwoRole", @@ -149,69 +212,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiOne" - } - } - ] - } - } - }, - "MyApiOneDeployment46fb22a429": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiOne" - }, - "Description": "RestApi deployment id: 46fb22a42926db6f64e09966936d074ec6bb9392", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionTwo" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiTwo" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -224,120 +255,89 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessApiKey": { + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": { + "Ref": "MyApiOneProdStage" } }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + { + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": { + "Ref": "MyApiTwoProdStage" } } - } - } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessUsagePlan": { + "DependsOn": [ + "MyApiOne", + "MyApiTwo" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiOne" + }, + "Stage": { + "Ref": "MyApiOneProdStage" } }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + { + "ApiId": { + "Ref": "MyApiTwo" + }, + "Stage": { + "Ref": "MyApiTwoProdStage" } } - } - } + ] + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", + "ServerlessUsagePlanKey": { + "DependsOn": [ + "ServerlessApiKey" + ], "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] + "KeyId": { + "Ref": "ServerlessApiKey" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "ServerlessUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_usageplans_shared_no_side_effect_2.json b/tests/translator/output/api_with_usageplans_shared_no_side_effect_2.json index 1c521417e8..b3c9704b44 100644 --- a/tests/translator/output/api_with_usageplans_shared_no_side_effect_2.json +++ b/tests/translator/output/api_with_usageplans_shared_no_side_effect_2.json @@ -1,191 +1,191 @@ { "Resources": { "MyApiFour": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/path/four": { "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionFour.Arn}/invocations" } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "api_key": { - "type": "apiKey", + "in": "header", "name": "x-api-key", - "in": "header" + "type": "apiKey" } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionFourRole": { - "Type": "AWS::IAM::Role", + "MyApiFourDeploymente7cfed53d1": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Description": "RestApi deployment id: e7cfed53d17a05b03ea5e2606faa4f13707b32f8", + "RestApiId": { + "Ref": "MyApiFour" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiFourProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiFourDeploymente7cfed53d1" + }, + "RestApiId": { + "Ref": "MyApiFour" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionFour": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionFourRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionFourApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionFour" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/four", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiFour" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionFour": { - "Type": "AWS::Lambda::Function", + "MyFunctionFourRole": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionFourRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "ServerlessApiKey": { + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiFour" }, - "Stage": { + "StageName": { "Ref": "MyApiFourProdStage" } } ] }, + "Type": "AWS::ApiGateway::ApiKey" + }, + "ServerlessUsagePlan": { "DependsOn": [ "MyApiFour" - ] - }, - "MyApiFourDeploymente7cfed53d1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiFour" - }, - "Description": "RestApi deployment id: e7cfed53d17a05b03ea5e2606faa4f13707b32f8", - "StageName": "Stage" - } - }, - "MyApiFourProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiFourDeploymente7cfed53d1" - }, - "RestApiId": { - "Ref": "MyApiFour" - }, - "StageName": "Prod" - } - }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiFour" }, - "StageName": { + "Stage": { "Ref": "MyApiFourProdStage" } } ] }, - "DependsOn": [ - "ServerlessUsagePlan" - ] + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "DependsOn": [ + "ServerlessApiKey" + ], "Properties": { - "KeyType": "API_KEY", "KeyId": { "Ref": "ServerlessApiKey" }, + "KeyType": "API_KEY", "UsagePlanId": { "Ref": "ServerlessUsagePlan" } }, - "DependsOn": [ - "ServerlessApiKey" - ] + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/api_with_xray_tracing.json b/tests/translator/output/api_with_xray_tracing.json index 04fb1acb40..f9c0e67359 100644 --- a/tests/translator/output/api_with_xray_tracing.json +++ b/tests/translator/output/api_with_xray_tracing.json @@ -1,37 +1,25 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "HtmlApiDeploymentf117c932f7" @@ -41,68 +29,80 @@ }, "StageName": "Prod", "TracingEnabled": true - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "HtmlFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - } - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/application_preparing_state.json b/tests/translator/output/application_preparing_state.json index 92fe7cc8d7..9129453a05 100644 --- a/tests/translator/output/application_preparing_state.json +++ b/tests/translator/output/application_preparing_state.json @@ -1,24 +1,24 @@ { "Resources": { "PreparingApplication": { - "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" }, { - "Value": "preparing", - "Key": "serverlessrepo:applicationId" + "Key": "serverlessrepo:applicationId", + "Value": "preparing" }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" } } } diff --git a/tests/translator/output/application_with_intrinsics.json b/tests/translator/output/application_with_intrinsics.json index d0fa434116..171b7a958e 100644 --- a/tests/translator/output/application_with_intrinsics.json +++ b/tests/translator/output/application_with_intrinsics.json @@ -1,76 +1,76 @@ { - "Parameters": { - "ApplicationIdParam": { - "Default": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Type": "String" - }, - "VersionParam": { - "Default": "1.0.0", - "Type": "String" - } - }, "Mappings": { "ApplicationLocations": { + "ap-southeast-1": { + "ApplicationId": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world", + "Version": "1.0.1" + }, "cn-north-1": { - "Version": "1.0.2", - "ApplicationId": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world" - }, + "ApplicationId": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world", + "Version": "1.0.2" + }, "us-gov-west-1": { - "Version": "1.0.3", - "ApplicationId": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world" - }, - "ap-southeast-1": { - "Version": "1.0.1", - "ApplicationId": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world" + "ApplicationId": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world", + "Version": "1.0.3" } } - }, + }, + "Parameters": { + "ApplicationIdParam": { + "Default": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Type": "String" + }, + "VersionParam": { + "Default": "1.0.0", + "Type": "String" + } + }, "Resources": { "ApplicationFindInMap": { - "Type": "AWS::CloudFormation::Stack", "Properties": { "NotificationARNs": [ { "Ref": "Sns" } - ], - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world" + }, { - "Value": "1.0.1", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.1" } - ] - } - }, + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, "ApplicationRefParameter": { - "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "1.0.0", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.0" } - ] - } - }, + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, "Sns": { "Type": "AWS::SNS::Topic" } diff --git a/tests/translator/output/aws-cn/alexa_skill.json b/tests/translator/output/aws-cn/alexa_skill.json index 73a380102c..12a7638c11 100644 --- a/tests/translator/output/aws-cn/alexa_skill.json +++ b/tests/translator/output/aws-cn/alexa_skill.json @@ -1,72 +1,72 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", + "AlexaSkillFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/alexa_skill_with_skill_id.json b/tests/translator/output/aws-cn/alexa_skill_with_skill_id.json index c623420fad..850985c86e 100644 --- a/tests/translator/output/aws-cn/alexa_skill_with_skill_id.json +++ b/tests/translator/output/aws-cn/alexa_skill_with_skill_id.json @@ -1,73 +1,73 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, - "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, + "Resources": { + "AlexaSkillFunc": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com", - "EventSourceToken": "amzn1.ask.skill.12345678-1234-1234-1234-123456789" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Tags": [ + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "EventSourceToken": "amzn1.ask.skill.12345678-1234-1234-1234-123456789", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } +} diff --git a/tests/translator/output/aws-cn/all_policy_templates.json b/tests/translator/output/aws-cn/all_policy_templates.json index 7ba527e40c..32ef7515ba 100644 --- a/tests/translator/output/aws-cn/all_policy_templates.json +++ b/tests/translator/output/aws-cn/all_policy_templates.json @@ -1,1500 +1,1498 @@ { "Resources": { "KitchenSinkFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "KitchenSinkFunctionRole", + "KitchenSinkFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "KitchenSinkFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "KitchenSinkFunctionRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "sqs:ChangeMessageVisibility", - "sqs:ChangeMessageVisibilityBatch", - "sqs:DeleteMessage", - "sqs:DeleteMessageBatch", - "sqs:GetQueueAttributes", + "sqs:ChangeMessageVisibility", + "sqs:ChangeMessageVisibilityBatch", + "sqs:DeleteMessage", + "sqs:DeleteMessageBatch", + "sqs:GetQueueAttributes", "sqs:ReceiveMessage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy0" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { "functionName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy1" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ "cloudwatch:DescribeAlarmHistory" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy2" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy3", "PolicyDocument": { "Statement": [ { "Action": [ "cloudwatch:PutMetricData" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy3" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy4", "PolicyDocument": { "Statement": [ { "Action": [ - "ec2:DescribeRegions", + "ec2:DescribeRegions", "ec2:DescribeInstances" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy4" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy5", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:GetItem", - "dynamodb:DeleteItem", - "dynamodb:PutItem", - "dynamodb:Scan", - "dynamodb:Query", - "dynamodb:UpdateItem", - "dynamodb:BatchWriteItem", - "dynamodb:BatchGetItem", - "dynamodb:DescribeTable", + "dynamodb:GetItem", + "dynamodb:DeleteItem", + "dynamodb:PutItem", + "dynamodb:Scan", + "dynamodb:Query", + "dynamodb:UpdateItem", + "dynamodb:BatchWriteItem", + "dynamodb:BatchGetItem", + "dynamodb:DescribeTable", "dynamodb:ConditionCheckItem" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", { "tableName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy5" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy6", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:GetItem", - "dynamodb:Scan", - "dynamodb:Query", - "dynamodb:BatchGetItem", + "dynamodb:GetItem", + "dynamodb:Scan", + "dynamodb:Query", + "dynamodb:BatchGetItem", "dynamodb:DescribeTable" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", { "tableName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy6" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy7", "PolicyDocument": { "Statement": [ { "Action": [ "ses:SendBounce" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy7" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy8", "PolicyDocument": { "Statement": [ { "Action": [ - "es:ESHttpPost", + "es:ESHttpPost", "es:ESHttpPut" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain/${domainName}/*", + "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain/${domainName}/*", { "domainName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy8" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy9", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetObjectVersion", + "s3:GetObject", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetObjectVersion", "s3:GetLifecycleConfiguration" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy9" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy10", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:GetLifecycleConfiguration", - "s3:PutLifecycleConfiguration", + "s3:GetObject", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetLifecycleConfiguration", + "s3:PutLifecycleConfiguration", "s3:DeleteObject" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy10" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy11", "PolicyDocument": { "Statement": [ { "Action": [ "ec2:DescribeImages" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy11" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy12", "PolicyDocument": { "Statement": [ { "Action": [ "cloudformation:DescribeStacks" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/*" - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy12" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy13", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CompareFaces", - "rekognition:DetectFaces", - "rekognition:DetectLabels", + "rekognition:CompareFaces", + "rekognition:DetectFaces", + "rekognition:DetectLabels", "rekognition:DetectModerationLabels" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy13" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy14", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:ListCollections", - "rekognition:ListFaces", - "rekognition:SearchFaces", + "rekognition:ListCollections", + "rekognition:ListFaces", + "rekognition:SearchFaces", "rekognition:SearchFacesByImage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy14" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy15", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CreateCollection", + "rekognition:CreateCollection", "rekognition:IndexFaces" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy15" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy16", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy16" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy17", "PolicyDocument": { "Statement": [ { "Action": [ "sns:Publish" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}", + "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}", { "topicName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy17" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy18", "PolicyDocument": { "Statement": [ { "Action": [ - "ec2:CreateNetworkInterface", - "ec2:DeleteNetworkInterface", - "ec2:DescribeNetworkInterfaces", + "ec2:CreateNetworkInterface", + "ec2:DeleteNetworkInterface", + "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy18" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy19", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:DescribeStream", - "dynamodb:GetRecords", + "dynamodb:DescribeStream", + "dynamodb:GetRecords", "dynamodb:GetShardIterator" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/${streamName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/${streamName}", { - "streamName": "name", + "streamName": "name", "tableName": "name" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ "dynamodb:ListStreams" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/*", { "tableName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy19" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy20", "PolicyDocument": { "Statement": [ { "Action": [ - "kinesis:ListStreams", + "kinesis:ListStreams", "kinesis:DescribeLimits" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/*" - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "kinesis:DescribeStream", - "kinesis:DescribeStreamSummary", - "kinesis:GetRecords", + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetRecords", "kinesis:GetShardIterator" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", + "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", { "streamName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy20" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy21", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:GetIdentityVerificationAttributes", - "ses:SendEmail", - "ses:SendRawEmail", + "ses:GetIdentityVerificationAttributes", + "ses:SendEmail", + "ses:SendRawEmail", "ses:VerifyEmailIdentity" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy21" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy22", "PolicyDocument": { "Statement": [ { "Action": [ - "sns:ListSubscriptionsByTopic", - "sns:CreateTopic", - "sns:SetTopicAttributes", - "sns:Subscribe", + "sns:ListSubscriptionsByTopic", + "sns:CreateTopic", + "sns:SetTopicAttributes", + "sns:Subscribe", "sns:Publish" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}*", + "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}*", { "topicName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy22" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy23", "PolicyDocument": { "Statement": [ { "Action": [ - "kinesis:AddTagsToStream", - "kinesis:CreateStream", - "kinesis:DecreaseStreamRetentionPeriod", - "kinesis:DeleteStream", - "kinesis:DescribeStream", - "kinesis:DescribeStreamSummary", - "kinesis:GetShardIterator", - "kinesis:IncreaseStreamRetentionPeriod", - "kinesis:ListTagsForStream", - "kinesis:MergeShards", - "kinesis:PutRecord", - "kinesis:PutRecords", - "kinesis:SplitShard", + "kinesis:AddTagsToStream", + "kinesis:CreateStream", + "kinesis:DecreaseStreamRetentionPeriod", + "kinesis:DeleteStream", + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetShardIterator", + "kinesis:IncreaseStreamRetentionPeriod", + "kinesis:ListTagsForStream", + "kinesis:MergeShards", + "kinesis:PutRecord", + "kinesis:PutRecords", + "kinesis:SplitShard", "kinesis:RemoveTagsFromStream" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", + "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", { "streamName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy23" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy24", "PolicyDocument": { "Statement": [ { - "Action": "kms:Decrypt", + "Action": "kms:Decrypt", + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", + "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", { "keyId": "keyId" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy24" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy25", "PolicyDocument": { "Statement": [ { "Action": [ - "polly:GetLexicon", + "polly:GetLexicon", "polly:DeleteLexicon" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/${lexiconName}", + "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/${lexiconName}", { "lexiconName": "name" } ] } - ], - "Effect": "Allow" - }, + ] + }, { "Action": [ - "polly:DescribeVoices", - "polly:ListLexicons", - "polly:PutLexicon", + "polly:DescribeVoices", + "polly:ListLexicons", + "polly:PutLexicon", "polly:SynthesizeSpeech" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/*" } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy25" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy26", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:GetObjectAcl", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:DeleteObject", - "s3:DeleteObjectTagging", - "s3:DeleteObjectVersionTagging", - "s3:GetObjectTagging", - "s3:GetObjectVersionTagging", - "s3:PutObjectTagging", + "s3:GetObject", + "s3:GetObjectAcl", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:DeleteObject", + "s3:DeleteObjectTagging", + "s3:DeleteObjectVersionTagging", + "s3:GetObjectTagging", + "s3:GetObjectVersionTagging", + "s3:PutObjectTagging", "s3:PutObjectVersionTagging" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" - }, + ] + }, { "Action": [ - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetLifecycleConfiguration", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetLifecycleConfiguration", "s3:PutLifecycleConfiguration" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy26" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy27", "PolicyDocument": { "Statement": [ { "Action": [ - "codepipeline:PutJobSuccessResult", + "codepipeline:PutJobSuccessResult", "codepipeline:PutJobFailureResult" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy27" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy28", "PolicyDocument": { "Statement": [ { "Action": [ - "serverlessrepo:CreateApplication", - "serverlessrepo:CreateApplicationVersion", - "serverlessrepo:UpdateApplication", - "serverlessrepo:GetApplication", - "serverlessrepo:ListApplications", - "serverlessrepo:ListApplicationVersions", + "serverlessrepo:CreateApplication", + "serverlessrepo:CreateApplicationVersion", + "serverlessrepo:UpdateApplication", + "serverlessrepo:GetApplication", + "serverlessrepo:ListApplications", + "serverlessrepo:ListApplicationVersions", "serverlessrepo:ListApplicationDependencies" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:serverlessrepo:${AWS::Region}:${AWS::AccountId}:applications/*" } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy28" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy29", "PolicyDocument": { "Statement": [ { "Action": [ "ec2:CopyImage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:image/${imageId}", + "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:image/${imageId}", { "imageId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy29" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy30", "PolicyDocument": { "Statement": [ { "Action": [ "codepipeline:ListPipelineExecutions" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipelinename}", + "arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipelinename}", { "pipelinename": "pipeline" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy30" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy31", "PolicyDocument": { "Statement": [ { "Action": [ - "cloudwatch:GetDashboard", - "cloudwatch:ListDashboards", - "cloudwatch:PutDashboard", + "cloudwatch:GetDashboard", + "cloudwatch:ListDashboards", + "cloudwatch:PutDashboard", "cloudwatch:ListMetrics" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy31" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy32", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CompareFaces", + "rekognition:CompareFaces", "rekognition:DetectFaces" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy32" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy33", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:DetectLabels", + "rekognition:DetectLabels", "rekognition:DetectModerationLabels" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy33" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy34", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:CreateBackup", + "dynamodb:CreateBackup", "dynamodb:DescribeContinuousBackups" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "table" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "dynamodb:DeleteBackup", - "dynamodb:DescribeBackup", + "dynamodb:DeleteBackup", + "dynamodb:DescribeBackup", "dynamodb:ListBackups" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", { "tableName": "table" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy34" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy35", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:RestoreTableFromBackup" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", { "tableName": "table" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "dynamodb:PutItem", - "dynamodb:UpdateItem", - "dynamodb:DeleteItem", - "dynamodb:GetItem", - "dynamodb:Query", - "dynamodb:Scan", + "dynamodb:PutItem", + "dynamodb:UpdateItem", + "dynamodb:DeleteItem", + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", "dynamodb:BatchWriteItem" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "table" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy35" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy36", "PolicyDocument": { "Statement": [ { "Action": [ - "comprehend:BatchDetectKeyPhrases", - "comprehend:DetectDominantLanguage", - "comprehend:DetectEntities", - "comprehend:BatchDetectEntities", - "comprehend:DetectKeyPhrases", - "comprehend:DetectSentiment", - "comprehend:BatchDetectDominantLanguage", + "comprehend:BatchDetectKeyPhrases", + "comprehend:DetectDominantLanguage", + "comprehend:DetectEntities", + "comprehend:BatchDetectEntities", + "comprehend:DetectKeyPhrases", + "comprehend:DetectSentiment", + "comprehend:BatchDetectDominantLanguage", "comprehend:BatchDetectSentiment" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy36" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy37", "PolicyDocument": { "Statement": [ { "Action": [ - "secretsmanager:DescribeSecret", - "secretsmanager:GetSecretValue", - "secretsmanager:PutSecretValue", + "secretsmanager:DescribeSecret", + "secretsmanager:GetSecretValue", + "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" - ], - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" - }, - "Effect": "Allow", + ], "Condition": { "StringEquals": { "secretsmanager:resource/AllowRotationLambdaArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}", { "functionName": "function" } ] } } + }, + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" } - }, + }, { "Action": [ "secretsmanager:GetRandomPassword" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy37" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy38", "PolicyDocument": { "Statement": [ { "Action": [ "mobileanalytics:PutEvents" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy38" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy39", "PolicyDocument": { "Statement": [ { "Action": [ - "mobiletargeting:GetEndpoint", - "mobiletargeting:UpdateEndpoint", + "mobiletargeting:GetEndpoint", + "mobiletargeting:UpdateEndpoint", "mobiletargeting:UpdateEndpointsBatch" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${pinpointApplicationId}/endpoints/*", + "arn:${AWS::Partition}:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${pinpointApplicationId}/endpoints/*", { "pinpointApplicationId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy39" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy40", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:DetectFaces", - "rekognition:DetectLabels", - "rekognition:DetectModerationLabels", + "rekognition:DetectFaces", + "rekognition:DetectLabels", + "rekognition:DetectModerationLabels", "rekognition:DetectText" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy40" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy41", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:IndexFaces", - "rekognition:DeleteFaces", - "rekognition:SearchFaces", - "rekognition:SearchFacesByImage", + "rekognition:IndexFaces", + "rekognition:DeleteFaces", + "rekognition:SearchFaces", + "rekognition:SearchFacesByImage", "rekognition:ListFaces" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "collection" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy41" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy42", "PolicyDocument": { "Statement": [ { "Action": [ - "eks:DescribeCluster", + "eks:DescribeCluster", "eks:ListClusters" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy42" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy43", "PolicyDocument": { "Statement": [ { "Action": [ - "ce:GetCostAndUsage", - "ce:GetDimensionValues", - "ce:GetReservationCoverage", - "ce:GetReservationPurchaseRecommendation", - "ce:GetReservationUtilization", + "ce:GetCostAndUsage", + "ce:GetDimensionValues", + "ce:GetReservationCoverage", + "ce:GetReservationPurchaseRecommendation", + "ce:GetReservationUtilization", "ce:GetTags" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy43" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy44", "PolicyDocument": { "Statement": [ { "Action": [ "organizations:ListAccounts" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy44" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy45", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:UpdateTable" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy45" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy46", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:GetIdentityVerificationAttributes", - "ses:SendEmail", - "ses:SendRawEmail", - "ses:SendTemplatedEmail", - "ses:SendBulkTemplatedEmail", + "ses:GetIdentityVerificationAttributes", + "ses:SendEmail", + "ses:SendRawEmail", + "ses:SendTemplatedEmail", + "ses:SendBulkTemplatedEmail", "ses:VerifyEmailIdentity" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy46" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy47", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:CreateTemplate", - "ses:GetTemplate", - "ses:ListTemplates", - "ses:UpdateTemplate", - "ses:DeleteTemplate", + "ses:CreateTemplate", + "ses:GetTemplate", + "ses:ListTemplates", + "ses:UpdateTemplate", + "ses:DeleteTemplate", "ses:TestRenderTemplate" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy47" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy48", "PolicyDocument": { "Statement": [ { "Action": [ "logs:FilterLogEvents" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${logGroupName}:log-stream:*", + "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${logGroupName}:log-stream:*", { "logGroupName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy48" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy49", "PolicyDocument": { "Statement": [ { "Action": [ "ssm:DescribeParameters" - ], - "Resource": "*", - "Effect": "Allow" - }, + ], + "Effect": "Allow", + "Resource": "*" + }, { "Action": [ - "ssm:GetParameters", - "ssm:GetParameter", + "ssm:GetParameters", + "ssm:GetParameter", "ssm:GetParametersByPath" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${parameterName}", + "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${parameterName}", { "parameterName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy49" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy50", "PolicyDocument": { "Statement": [ { "Action": [ "states:StartExecution" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy50" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy51", "PolicyDocument": { "Statement": [ { "Action": [ - "codecommit:GitPull", - "codecommit:GitPush", - "codecommit:CreateBranch", - "codecommit:DeleteBranch", - "codecommit:GetBranch", - "codecommit:ListBranches", - "codecommit:MergeBranchesByFastForward", - "codecommit:MergeBranchesBySquash", - "codecommit:MergeBranchesByThreeWay", - "codecommit:UpdateDefaultBranch", - "codecommit:BatchDescribeMergeConflicts", - "codecommit:CreateUnreferencedMergeCommit", - "codecommit:DescribeMergeConflicts", - "codecommit:GetMergeCommit", - "codecommit:GetMergeOptions", - "codecommit:BatchGetPullRequests", - "codecommit:CreatePullRequest", - "codecommit:DescribePullRequestEvents", - "codecommit:GetCommentsForPullRequest", - "codecommit:GetCommitsFromMergeBase", - "codecommit:GetMergeConflicts", - "codecommit:GetPullRequest", - "codecommit:ListPullRequests", - "codecommit:MergePullRequestByFastForward", - "codecommit:MergePullRequestBySquash", - "codecommit:MergePullRequestByThreeWay", - "codecommit:PostCommentForPullRequest", - "codecommit:UpdatePullRequestDescription", - "codecommit:UpdatePullRequestStatus", - "codecommit:UpdatePullRequestTitle", - "codecommit:DeleteFile", - "codecommit:GetBlob", - "codecommit:GetFile", - "codecommit:GetFolder", - "codecommit:PutFile", - "codecommit:DeleteCommentContent", - "codecommit:GetComment", - "codecommit:GetCommentsForComparedCommit", - "codecommit:PostCommentForComparedCommit", - "codecommit:PostCommentReply", - "codecommit:UpdateComment", - "codecommit:BatchGetCommits", - "codecommit:CreateCommit", - "codecommit:GetCommit", - "codecommit:GetCommitHistory", - "codecommit:GetDifferences", - "codecommit:GetObjectIdentifier", - "codecommit:GetReferences", - "codecommit:GetTree", - "codecommit:GetRepository", - "codecommit:UpdateRepositoryDescription", - "codecommit:ListTagsForResource", - "codecommit:TagResource", - "codecommit:UntagResource", - "codecommit:GetRepositoryTriggers", - "codecommit:PutRepositoryTriggers", - "codecommit:TestRepositoryTriggers", - "codecommit:GetBranch", - "codecommit:GetCommit", - "codecommit:UploadArchive", - "codecommit:GetUploadArchiveStatus", + "codecommit:GitPull", + "codecommit:GitPush", + "codecommit:CreateBranch", + "codecommit:DeleteBranch", + "codecommit:GetBranch", + "codecommit:ListBranches", + "codecommit:MergeBranchesByFastForward", + "codecommit:MergeBranchesBySquash", + "codecommit:MergeBranchesByThreeWay", + "codecommit:UpdateDefaultBranch", + "codecommit:BatchDescribeMergeConflicts", + "codecommit:CreateUnreferencedMergeCommit", + "codecommit:DescribeMergeConflicts", + "codecommit:GetMergeCommit", + "codecommit:GetMergeOptions", + "codecommit:BatchGetPullRequests", + "codecommit:CreatePullRequest", + "codecommit:DescribePullRequestEvents", + "codecommit:GetCommentsForPullRequest", + "codecommit:GetCommitsFromMergeBase", + "codecommit:GetMergeConflicts", + "codecommit:GetPullRequest", + "codecommit:ListPullRequests", + "codecommit:MergePullRequestByFastForward", + "codecommit:MergePullRequestBySquash", + "codecommit:MergePullRequestByThreeWay", + "codecommit:PostCommentForPullRequest", + "codecommit:UpdatePullRequestDescription", + "codecommit:UpdatePullRequestStatus", + "codecommit:UpdatePullRequestTitle", + "codecommit:DeleteFile", + "codecommit:GetBlob", + "codecommit:GetFile", + "codecommit:GetFolder", + "codecommit:PutFile", + "codecommit:DeleteCommentContent", + "codecommit:GetComment", + "codecommit:GetCommentsForComparedCommit", + "codecommit:PostCommentForComparedCommit", + "codecommit:PostCommentReply", + "codecommit:UpdateComment", + "codecommit:BatchGetCommits", + "codecommit:CreateCommit", + "codecommit:GetCommit", + "codecommit:GetCommitHistory", + "codecommit:GetDifferences", + "codecommit:GetObjectIdentifier", + "codecommit:GetReferences", + "codecommit:GetTree", + "codecommit:GetRepository", + "codecommit:UpdateRepositoryDescription", + "codecommit:ListTagsForResource", + "codecommit:TagResource", + "codecommit:UntagResource", + "codecommit:GetRepositoryTriggers", + "codecommit:PutRepositoryTriggers", + "codecommit:TestRepositoryTriggers", + "codecommit:GetBranch", + "codecommit:GetCommit", + "codecommit:UploadArchive", + "codecommit:GetUploadArchiveStatus", "codecommit:CancelUploadArchive" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", + "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", { "repositoryName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy51" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy52", "PolicyDocument": { "Statement": [ { "Action": [ - "codecommit:GitPull", - "codecommit:GetBranch", - "codecommit:ListBranches", - "codecommit:BatchDescribeMergeConflicts", - "codecommit:DescribeMergeConflicts", - "codecommit:GetMergeCommit", - "codecommit:GetMergeOptions", - "codecommit:BatchGetPullRequests", - "codecommit:DescribePullRequestEvents", - "codecommit:GetCommentsForPullRequest", - "codecommit:GetCommitsFromMergeBase", - "codecommit:GetMergeConflicts", - "codecommit:GetPullRequest", - "codecommit:ListPullRequests", - "codecommit:GetBlob", - "codecommit:GetFile", - "codecommit:GetFolder", - "codecommit:GetComment", - "codecommit:GetCommentsForComparedCommit", - "codecommit:BatchGetCommits", - "codecommit:GetCommit", - "codecommit:GetCommitHistory", - "codecommit:GetDifferences", - "codecommit:GetObjectIdentifier", - "codecommit:GetReferences", - "codecommit:GetTree", - "codecommit:GetRepository", - "codecommit:ListTagsForResource", - "codecommit:GetRepositoryTriggers", - "codecommit:TestRepositoryTriggers", - "codecommit:GetBranch", - "codecommit:GetCommit", + "codecommit:GitPull", + "codecommit:GetBranch", + "codecommit:ListBranches", + "codecommit:BatchDescribeMergeConflicts", + "codecommit:DescribeMergeConflicts", + "codecommit:GetMergeCommit", + "codecommit:GetMergeOptions", + "codecommit:BatchGetPullRequests", + "codecommit:DescribePullRequestEvents", + "codecommit:GetCommentsForPullRequest", + "codecommit:GetCommitsFromMergeBase", + "codecommit:GetMergeConflicts", + "codecommit:GetPullRequest", + "codecommit:ListPullRequests", + "codecommit:GetBlob", + "codecommit:GetFile", + "codecommit:GetFolder", + "codecommit:GetComment", + "codecommit:GetCommentsForComparedCommit", + "codecommit:BatchGetCommits", + "codecommit:GetCommit", + "codecommit:GetCommitHistory", + "codecommit:GetDifferences", + "codecommit:GetObjectIdentifier", + "codecommit:GetReferences", + "codecommit:GetTree", + "codecommit:GetRepository", + "codecommit:ListTagsForResource", + "codecommit:GetRepositoryTriggers", + "codecommit:TestRepositoryTriggers", + "codecommit:GetBranch", + "codecommit:GetCommit", "codecommit:GetUploadArchiveStatus" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", + "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", { "repositoryName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy52" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy53", "PolicyDocument": { "Statement": [ { - "Action": "kms:Encrypt", + "Action": "kms:Encrypt", + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", + "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", { "keyId": "keyId" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy53" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy54", "PolicyDocument": { "Statement": [ { "Action": [ - "athena:ListWorkGroups", - "athena:GetExecutionEngine", - "athena:GetExecutionEngines", - "athena:GetNamespace", - "athena:GetCatalogs", - "athena:GetNamespaces", - "athena:GetTables", + "athena:ListWorkGroups", + "athena:GetExecutionEngine", + "athena:GetExecutionEngines", + "athena:GetNamespace", + "athena:GetCatalogs", + "athena:GetNamespaces", + "athena:GetTables", "athena:GetTable" - ], - "Resource": "*", - "Effect": "Allow" - }, - { - "Action": [ - "athena:StartQueryExecution", - "athena:GetQueryResults", - "athena:DeleteNamedQuery", - "athena:GetNamedQuery", - "athena:ListQueryExecutions", - "athena:StopQueryExecution", - "athena:GetQueryResultsStream", - "athena:ListNamedQueries", - "athena:CreateNamedQuery", - "athena:GetQueryExecution", - "athena:BatchGetNamedQuery", - "athena:BatchGetQueryExecution", + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "athena:StartQueryExecution", + "athena:GetQueryResults", + "athena:DeleteNamedQuery", + "athena:GetNamedQuery", + "athena:ListQueryExecutions", + "athena:StopQueryExecution", + "athena:GetQueryResultsStream", + "athena:ListNamedQueries", + "athena:CreateNamedQuery", + "athena:GetQueryExecution", + "athena:BatchGetNamedQuery", + "athena:BatchGetQueryExecution", "athena:GetWorkGroup" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/${workgroupName}", + "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/${workgroupName}", { "workgroupName": "name" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy54" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy55", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:PutLifecycleConfiguration" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -1515,19 +1513,19 @@ ] } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy55" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy56", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "dynamodb:PutItem", "dynamodb:UpdateItem", "dynamodb:BatchWriteItem" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -1548,14 +1546,15 @@ ] } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy56" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy57", "PolicyDocument": { "Statement": [ { "Action": "events:PutEvents", + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBusName}", @@ -1563,20 +1562,20 @@ "eventBusName": "name" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy57" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy58", "PolicyDocument": { "Statement": [ { "Action": [ "acm:GetCertificate" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${certificateArn}", @@ -1584,20 +1583,20 @@ "certificateArn": "arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy58" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy59", "PolicyDocument": { "Statement": [ { "Action": [ "route53:ChangeResourceRecordSets" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:route53:::hostedzone/${HostedZoneId}", @@ -1605,20 +1604,21 @@ "HostedZoneId": "test" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy59" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_cache.json b/tests/translator/output/aws-cn/api_cache.json index c087e47218..da6c894752 100644 --- a/tests/translator/output/aws-cn/api_cache.json +++ b/tests/translator/output/aws-cn/api_cache.json @@ -1,117 +1,117 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { - "CacheClusterEnabled": true, + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", "DeploymentId": { "Ref": "HtmlApiDeploymentf117c932f7" - }, + }, "RestApiId": { "Ref": "HtmlApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6" - } - }, + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_description.json b/tests/translator/output/aws-cn/api_description.json index f5277b61d5..dc7bf5ffa2 100644 --- a/tests/translator/output/aws-cn/api_description.json +++ b/tests/translator/output/aws-cn/api_description.json @@ -1,81 +1,9 @@ { "Resources": { - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "Api" - }, - "StageName": "Prod" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "Api" - } - ] - } - } - }, - "ApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, "Api": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "BodyS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "webpage_swagger.json" }, "Description": "my description", @@ -87,30 +15,102 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "Api", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_endpoint_configuration.json b/tests/translator/output/aws-cn/api_endpoint_configuration.json index a4ccfefcc2..a5ebb82163 100644 --- a/tests/translator/output/aws-cn/api_endpoint_configuration.json +++ b/tests/translator/output/aws-cn/api_endpoint_configuration.json @@ -5,14 +5,52 @@ } }, "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -22,145 +60,84 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcb4fb12558" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcb4fb12558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -178,7 +155,30 @@ "Ref": "EndpointConfig" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcb4fb12558": { + "Properties": { + "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcb4fb12558" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_endpoint_configuration_with_vpcendpoint.json b/tests/translator/output/aws-cn/api_endpoint_configuration_with_vpcendpoint.json index f21a7b2d50..6980ca33ee 100644 --- a/tests/translator/output/aws-cn/api_endpoint_configuration_with_vpcendpoint.json +++ b/tests/translator/output/aws-cn/api_endpoint_configuration_with_vpcendpoint.json @@ -1,21 +1,64 @@ { "Parameters": { - "VpcEndpointId": { + "EndpointConfigType": { "Type": "String" }, - "EndpointConfigType": { + "VpcEndpointId": { "Type": "String" } }, "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ], + "VpcEndpointIds": [ + { + "Ref": "VpcEndpointId" + } + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -25,17 +68,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -48,141 +111,55 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "VpcEndpointIds": [ - { - "Ref": "VpcEndpointId" - } - ], - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcb4fb12558" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcb4fb12558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, "swagger": "2.0" }, "EndpointConfiguration": { - "VpcEndpointIds": [ + "Types": [ { - "Ref": "VpcEndpointId" + "Ref": "EndpointConfigType" } ], - "Types": [ + "VpcEndpointIds": [ { - "Ref": "EndpointConfigType" + "Ref": "VpcEndpointId" } ] }, @@ -191,7 +168,30 @@ "Ref": "EndpointConfigType" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcb4fb12558": { + "Properties": { + "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcb4fb12558" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_http_paths_with_if_condition.json b/tests/translator/output/aws-cn/api_http_paths_with_if_condition.json index 4a37bfebae..c5573de5bb 100644 --- a/tests/translator/output/aws-cn/api_http_paths_with_if_condition.json +++ b/tests/translator/output/aws-cn/api_http_paths_with_if_condition.json @@ -1,178 +1,178 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] }, - "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Description": "sam-app\nSample SAM Template for sam-app\n", + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } + } + }, + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + }, + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - } + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_else_case.json b/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_else_case.json index 625b1d6b3a..b2d07c09c1 100644 --- a/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_else_case.json +++ b/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_else_case.json @@ -1,166 +1,166 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] }, - "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Description": "sam-app\nSample SAM Template for sam-app\n", + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_then_case.json b/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_then_case.json index 9348929ad2..661a6de77c 100644 --- a/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_then_case.json +++ b/tests/translator/output/aws-cn/api_http_paths_with_if_condition_no_value_then_case.json @@ -1,66 +1,115 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", + "MyApi": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" + } } } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "Ref": "AWS::NoValue" + }, + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + } + }, + "Type": "AWS::ApiGatewayV2::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -80,87 +129,38 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + "MyAuthFnRole": { "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "Ref": "AWS::NoValue" - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ + "AssumeRolePolicyDocument": { + "Statement": [ { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_request_model.json b/tests/translator/output/aws-cn/api_request_model.json index ddda610e7a..b8c80d9c5f 100644 --- a/tests/translator/output/aws-cn/api_request_model.json +++ b/tests/translator/output/aws-cn/api_request_model.json @@ -1,195 +1,195 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment37c4e9609d" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlFunctionAnyPathPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", - { - "__ApiId__": "HtmlApi", - "__Stage__": "*" - } - ] - } - } - }, - "HtmlApiDeployment37c4e9609d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: 37c4e9609d82528be3f2388c7b7e80b7b78cd31f", - "StageName": "Stage" - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, "in": "body", "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "responses": {}, + } + } + }, + "/any": { + "x-amazon-apigateway-any-method": { "parameters": [ { "in": "body", "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" - }, - "required": true + } + } + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" } } } - } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeployment37c4e9609d": { + "Properties": { + "Description": "RestApi deployment id: 37c4e9609d82528be3f2388c7b7e80b7b78cd31f", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment37c4e9609d" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionAnyPathPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_request_model_openapi_3.json b/tests/translator/output/aws-cn/api_request_model_openapi_3.json index 8b4533ff27..a41f12a326 100644 --- a/tests/translator/output/aws-cn/api_request_model_openapi_3.json +++ b/tests/translator/output/aws-cn/api_request_model_openapi_3.json @@ -1,110 +1,37 @@ { "Resources": { - "HtmlApiDeploymentf84be626f3": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f84be626f359fc9697fd8e228c5ffe53e252f82c" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "components": { + "schemas": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" } - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentf84be626f3" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionIamPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "HtmlApi" + }, + "securitySchemes": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" } } - ] - } - } - }, - "HtmlFunctionAnyIamPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", - { - "__ApiId__": { - "Ref": "HtmlApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { - "/iam": { + "/": { "get": { "requestBody": { "content": { @@ -113,27 +40,21 @@ "$ref": "#/components/schemas/user" } } - }, + }, "required": true - }, + }, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } - }, - "/": { - "get": { + }, + "/any/iam": { + "x-amazon-apigateway-any-method": { "requestBody": { "content": { "application/json": { @@ -141,28 +62,8 @@ "$ref": "#/components/schemas/user" } } - }, - "required": true - }, - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any/iam": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" }, - "credentials": "arn:aws:iam::*:user/*" + "required": true }, "responses": {}, "security": [ @@ -170,6 +71,18 @@ "AWS_IAM": [] } ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } + } + }, + "/iam": { + "get": { "requestBody": { "content": { "application/json": { @@ -179,83 +92,170 @@ } }, "required": true - } - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - }, - "schemas": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + }, + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } } } } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf84be626f3": { + "Properties": { + "Description": "RestApi deployment id: f84be626f359fc9697fd8e228c5ffe53e252f82c", + "RestApiId": { + "Ref": "HtmlApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentf84be626f3" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionAnyIamPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionIamPermissionProd": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_request_model_with_validator.json b/tests/translator/output/aws-cn/api_request_model_with_validator.json index c392a23538..18ed557fd1 100644 --- a/tests/translator/output/aws-cn/api_request_model_with_validator.json +++ b/tests/translator/output/aws-cn/api_request_model_with_validator.json @@ -1,837 +1,837 @@ { "Resources": { - "HtmlFunctionOnlyBodyDefinitionFalse": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionOnlyBodyDefinitionFalseRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidationRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionOnlyRequestDefinitionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalseRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidation": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionNotDefinedValidationRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionNotDefinedValidation" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlFunctionMixinValidationRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentdf07d632f4" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/only-request-true": { + "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" - } - }, - "x-amazon-apigateway-request-validator": "params-only", - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-and-params", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-and-params" + } + }, + "/mixin": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/mixin": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionMixinValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-only", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-only" + } + }, + "/no-validation": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-request-false": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/not-defined": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-body-true": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-only", - "responses": {}, + } + } + }, + "/only-body-false": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/not-defined": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" } - }, - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/only-body-true": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/no-validation": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-only" + } + }, + "/only-request-false": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-body-false": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/only-request-true": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "params-only" } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-request-validators": { - "params-only": { - "validateRequestParameters": true, - "validateRequestBody": false - }, "body-and-params": { - "validateRequestParameters": true, - "validateRequestBody": true - }, - "no-validation": { - "validateRequestParameters": false, - "validateRequestBody": false - }, + "validateRequestBody": true, + "validateRequestParameters": true + }, "body-only": { - "validateRequestParameters": false, - "validateRequestBody": true - } - }, - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" - } - } + "validateRequestBody": true, + "validateRequestParameters": false + }, + "no-validation": { + "validateRequestBody": false, + "validateRequestParameters": false + }, + "params-only": { + "validateRequestBody": false, + "validateRequestParameters": true } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "HtmlFunctionOnlyBodyDefinitionFalseRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentdf07d632f4": { + "Properties": { + "Description": "RestApi deployment id: df07d632f424a561531bf71d3c41ea245b01d80e", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentdf07d632f4" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionMixinValidation": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionMixinValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionMixinValidationGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionMixinValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionMixinValidationRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalse": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionNoValidation": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionOnlyRequestDefinitionFalseRole", + "HtmlFunctionNoValidationRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionNoValidationGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNoValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionNoValidationRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionNotDefinedValidation": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionNotDefinedValidationRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionNoValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionNoValidation" - }, + "Ref": "HtmlFunctionNotDefinedValidation" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionNotDefinedValidationRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionOnlyRequestDefinition" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } - }, - "HtmlApiDeploymentdf07d632f4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: df07d632f424a561531bf71d3c41ea245b01d80e", - "StageName": "Stage" - } - }, - "HtmlFunctionOnlyRequestDefinition": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionOnlyRequestDefinitionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionNoValidation": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyBodyDefinition": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionNoValidationRole", + "HtmlFunctionOnlyBodyDefinitionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinition": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyBodyDefinitionFalse": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionOnlyBodyDefinitionRole", + "HtmlFunctionOnlyBodyDefinitionFalseRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" - }, + "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionNoValidationRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyBodyDefinitionFalseRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionMixinValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionMixinValidation" - }, + "Ref": "HtmlFunctionOnlyBodyDefinition" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionMixinValidation": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyBodyDefinitionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyRequestDefinition": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionMixinValidationRole", + "HtmlFunctionOnlyRequestDefinitionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinitionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyRequestDefinitionFalse": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyRequestDefinitionFalseRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" - }, + "Ref": "HtmlFunctionOnlyRequestDefinition" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyRequestDefinitionRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionOnlyBodyDefinition" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_request_model_with_validator_openapi_3.json b/tests/translator/output/aws-cn/api_request_model_with_validator_openapi_3.json index 57bf8cf6eb..fbd19c65d7 100644 --- a/tests/translator/output/aws-cn/api_request_model_with_validator_openapi_3.json +++ b/tests/translator/output/aws-cn/api_request_model_with_validator_openapi_3.json @@ -1,85 +1,27 @@ { "Resources": { - "HtmlApiDeploymentfa918fe8b6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: fa918fe8b68f65e882542b900cc422005ea1a7f6" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentfa918fe8b6" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "schemas": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { "/": { "get": { @@ -90,73 +32,131 @@ "$ref": "#/components/schemas/user" } } - }, + }, "required": true - }, + }, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-and-params", - "responses": {} + }, + "x-amazon-apigateway-request-validator": "body-and-params" } } - }, - "openapi": "3.0", - "components": { - "schemas": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" - } - } - } - } - }, + }, "x-amazon-apigateway-request-validators": { "body-and-params": { - "validateRequestParameters": true, - "validateRequestBody": true + "validateRequestBody": true, + "validateRequestParameters": true } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentfa918fe8b6": { + "Properties": { + "Description": "RestApi deployment id: fa918fe8b68f65e882542b900cc422005ea1a7f6", + "RestApiId": { + "Ref": "HtmlApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentfa918fe8b6" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi.json b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi.json index 1c4c0ffa18..0a7ed4b79d 100644 --- a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi.json +++ b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi.json @@ -1,178 +1,110 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment7a5169a458" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiDeployment7a5169a458": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7a5169a458f926127d35761e818069f54fb11c7e", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, "info": { "title": { "Fn::Sub": "${AWS::StackName}-Api" } }, + "openapi": "3.0", "paths": { "/post": { "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +113,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,57 +133,52 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] - } - }, - { - "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "1.0", "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, + "uri": "https://www.otherURI.co/" + } + } + }, + { "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -255,13 +187,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -270,63 +207,126 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment7a5169a458": { + "Properties": { + "Description": "RestApi deployment id: 7a5169a458f926127d35761e818069f54fb11c7e", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment7a5169a458" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_else_case.json b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_else_case.json index a2e3906c3b..39aad5aa12 100644 --- a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_else_case.json +++ b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_else_case.json @@ -1,33 +1,175 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": { + "Fn::Join": [ + ",", + [ + "www.amazon.com", + "www.google.com" + ] + ] + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, "MyApiDeployment295ec3a9fa": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 295ec3a9fa9a5e053050d7b4dbac15a1817604ea", "RestApiId": { "Ref": "MyApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -47,10 +189,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment295ec3a9fa" @@ -59,10 +201,10 @@ "Ref": "MyApi" }, "StageName": "dev" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -82,13 +224,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -101,7 +242,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -112,150 +254,8 @@ "Value": "SAM" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, - "options": { - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": { - "Fn::Join": [ - ",", - [ - "www.amazon.com", - "www.google.com" - ] - ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, - "summary": "CORS support", - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ], - "consumes": [ - "application/json" - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_then_case.json b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_then_case.json index 1906f8f8e0..8be6d8586a 100644 --- a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_then_case.json +++ b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_openapi_no_value_then_case.json @@ -1,23 +1,175 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "Ref": "AWS::NoValue" + }, + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": { + "Fn::Join": [ + ",", + [ + "www.amazon.com", + "www.google.com" + ] + ] + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentca11cc1e55": { + "Properties": { + "Description": "RestApi deployment id: ca11cc1e55c3bb45d10cfaa66b1487834342d5f3", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -37,20 +189,22 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeploymentca11cc1e55": { - "Type": "AWS::ApiGateway::Deployment", + "MyApidevStage": { "Properties": { - "Description": "RestApi deployment id: ca11cc1e55c3bb45d10cfaa66b1487834342d5f3", + "DeploymentId": { + "Ref": "MyApiDeploymentca11cc1e55" + }, "RestApiId": { "Ref": "MyApi" }, - "StageName": "Stage" - } + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -70,13 +224,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,7 +242,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -100,162 +254,8 @@ "Value": "SAM" } ] - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentca11cc1e55" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "Ref": "AWS::NoValue" - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, - "options": { - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": { - "Fn::Join": [ - ",", - [ - "www.amazon.com", - "www.google.com" - ] - ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, - "summary": "CORS support", - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ], - "consumes": [ - "application/json" - ] - } - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger.json b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger.json index 1eb31d516d..acac4c8a0e 100644 --- a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger.json +++ b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiDeployment026bbf40e9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 026bbf40e99f01b30b76b4864c11b99a6c1c84e1", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment026bbf40e9" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -128,51 +29,43 @@ "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +74,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,57 +94,52 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] - } - }, - { - "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "1.0", "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, + "uri": "https://www.otherURI.co/" + } + } + }, + { "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -255,13 +148,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -270,27 +168,29 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -305,26 +205,126 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment026bbf40e9": { + "Properties": { + "Description": "RestApi deployment id: 026bbf40e99f01b30b76b4864c11b99a6c1c84e1", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment026bbf40e9" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_else_case.json b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_else_case.json index 888a403458..057803978d 100644 --- a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_else_case.json +++ b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_else_case.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentab66684380" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiDeploymentab66684380": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: ab666843809d95c79e0c51e838e6f480276429c4", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -128,51 +29,43 @@ "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +74,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,9 +94,12 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } } }, { @@ -207,19 +108,18 @@ ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -234,26 +134,126 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentab66684380": { + "Properties": { + "Description": "RestApi deployment id: ab666843809d95c79e0c51e838e6f480276429c4", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentab66684380" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_then_case.json b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_then_case.json index 28f7fdcab3..bb83b0ebc8 100644 --- a/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_then_case.json +++ b/tests/translator/output/aws-cn/api_rest_paths_with_if_condition_swagger_no_value_then_case.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiDeploymente86593dd8d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: e86593dd8dc88a67504512de32e36fccc9ffa271", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymente86593dd8d" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -131,51 +32,43 @@ "Ref": "AWS::NoValue" }, { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -184,13 +77,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -199,27 +97,29 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -234,26 +134,126 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymente86593dd8d": { + "Properties": { + "Description": "RestApi deployment id: e86593dd8dc88a67504512de32e36fccc9ffa271", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymente86593dd8d" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_swagger_integration_with_ref_intrinsic_api_id.json b/tests/translator/output/aws-cn/api_swagger_integration_with_ref_intrinsic_api_id.json index cbf97cecee..516db3f4f0 100644 --- a/tests/translator/output/aws-cn/api_swagger_integration_with_ref_intrinsic_api_id.json +++ b/tests/translator/output/aws-cn/api_swagger_integration_with_ref_intrinsic_api_id.json @@ -1,172 +1,172 @@ { "Resources": { - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentda1577e1dd" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiDeploymentda1577e1dd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: da1577e1ddadc82fbcc104e2477852594eeb133c", - "StageName": "Stage" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "HtmlApi" - } - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "123456" + ] + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/", + "execute-api:/${__Stage__}/GET/", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": { - "AWS": [ - "123456" - ] - } - } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } + ] + }, + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentda1577e1dd": { + "Properties": { + "Description": "RestApi deployment id: da1577e1ddadc82fbcc104e2477852594eeb133c", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentda1577e1dd" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_swagger_integration_with_string_api_id.json b/tests/translator/output/aws-cn/api_swagger_integration_with_string_api_id.json index ffb4093864..fb47b0e89b 100644 --- a/tests/translator/output/aws-cn/api_swagger_integration_with_string_api_id.json +++ b/tests/translator/output/aws-cn/api_swagger_integration_with_string_api_id.json @@ -1,170 +1,170 @@ { "Resources": { - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentda1577e1dd" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiDeploymentda1577e1dd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: da1577e1ddadc82fbcc104e2477852594eeb133c", - "StageName": "Stage" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "123456" + ] + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/", + "execute-api:/${__Stage__}/GET/", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": { - "AWS": [ - "123456" - ] - } - } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } + ] + }, + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentda1577e1dd": { + "Properties": { + "Description": "RestApi deployment id: da1577e1ddadc82fbcc104e2477852594eeb133c", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentda1577e1dd" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_access_log_setting.json b/tests/translator/output/aws-cn/api_with_access_log_setting.json index 06436e91f8..ba6387852f 100644 --- a/tests/translator/output/aws-cn/api_with_access_log_setting.json +++ b/tests/translator/output/aws-cn/api_with_access_log_setting.json @@ -1,7 +1,49 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "AccessLogSetting": { + "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", + "Format": "$context.requestId" + }, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,153 +59,84 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "AccessLogSetting": { - "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", - "Format": "$context.requestId" - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "AccessLogSetting": { - "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", - "Format": "$context.requestId" - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcb4fb12558" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcb4fb12558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -177,7 +150,34 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcb4fb12558": { + "Properties": { + "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "AccessLogSetting": { + "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", + "Format": "$context.requestId" + }, + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcb4fb12558" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_any_method_in_swagger.json b/tests/translator/output/aws-cn/api_with_any_method_in_swagger.json index 44e182380e..bcab3b3d05 100644 --- a/tests/translator/output/aws-cn/api_with_any_method_in_swagger.json +++ b/tests/translator/output/aws-cn/api_with_any_method_in_swagger.json @@ -1,24 +1,31 @@ { "Resources": { - "MyApiStage": { - "Type": "AWS::ApiGateway::Stage", + "HttpApiFunction": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment37c803d096" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" }, - "RestApiId": { - "Ref": "MyApi" + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] }, - "StageName": { - "Ref": "Stage" - } - } + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -31,154 +38,122 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiDeployment37c803d096": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 37c803d09628334a047966047f087abf49267a2c", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "HttpApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "LambdaAuthorizer": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": null + } + ] + }, + "identitySource": "method.request.header.Authorization", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, "info": { "title": { "Fn::Sub": "${AWS::StackName}-Api" } }, + "openapi": "3.0", "paths": { "$default": { "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, "isDefaultRoute": true, + "responses": {}, "security": [ { "LambdaAuthorizer": [] } ], - "responses": {} + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } }, "/": { "any": { + "security": [ + { + "LambdaAuthorizer": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "ANY", + "payloadFormatVersion": "1.0", "type": "http_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, + "uri": "https://www.alphavantage.co/" + } + }, + "get": { + "responses": {}, "security": [ { "LambdaAuthorizer": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "2.0", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "LambdaAuthorizer": [] } - ], - "responses": {} - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "LambdaAuthorizer": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": null - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" + } } } } @@ -191,7 +166,32 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment37c803d096": { + "Properties": { + "Description": "RestApi deployment id: 37c803d09628334a047966047f087abf49267a2c", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment37c803d096" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": { + "Ref": "Stage" + } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_apikey_default_override.json b/tests/translator/output/aws-cn/api_with_apikey_default_override.json index 3369f0776a..b81698be7c 100644 --- a/tests/translator/output/aws-cn/api_with_apikey_default_override.json +++ b/tests/translator/output/aws-cn/api_with_apikey_default_override.json @@ -1,90 +1,112 @@ { "Resources": { - "MyApiWithAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAuthDeployment12e3363002" - }, - "RestApiId": { - "Ref": "MyApiWithAuth" - }, - "StageName": "Prod" - } - }, - "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithAuth": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredTrue" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyDefault": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredDefault.Arn}/invocations" + } + } + } + }, + "/ApiKeyFalse": { + "get": { + "responses": {}, + "security": [], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredFalse.Arn}/invocations" + } + } + } + }, + "/ApiKeyTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" + } + } } } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionWithApiKeyRequiredFalseMyApiWithApiKeyRequiredFalsePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithAuthDeployment12e3363002": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredFalse" + "Description": "RestApi deployment id: 12e33630022574b70be75950554db06d81af114d", + "RestApiId": { + "Ref": "MyApiWithAuth" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyFalse", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyFunctionWithApiKeyRequiredTrue": { - "Type": "AWS::Lambda::Function", + "MyApiWithAuthProdStage": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" + "DeploymentId": { + "Ref": "MyApiWithAuthDeployment12e3363002" }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithApiKeyRequiredTrueRole", - "Arn" - ] + "RestApiId": { + "Ref": "MyApiWithAuth" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyFunctionWithApiKeyRequiredDefault": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionWithApiKeyRequiredDefaultRole", @@ -94,51 +116,71 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionWithApiKeyRequiredDefaultMyApiWithApiKeyRequiredDefaultPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionWithApiKeyRequiredDefault" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyDefault", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithAuthDeployment12e3363002": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithApiKeyRequiredDefaultRole": { "Properties": { - "RestApiId": { - "Ref": "MyApiWithAuth" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: 12e33630022574b70be75950554db06d81af114d", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionWithApiKeyRequiredFalse": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionWithApiKeyRequiredFalseRole", @@ -148,26 +190,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredFalseMyApiWithApiKeyRequiredFalsePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyFalse", + { + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredFalseRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,54 +233,68 @@ ] } } - ] - } - } - }, - "MyFunctionWithApiKeyRequiredDefaultRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithApiKeyRequiredTrue": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithApiKeyRequiredTrueRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredTrue" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredTrueRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -240,87 +307,20 @@ ] } } - ] - } - } - }, - "MyApiWithAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyFalse": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredFalse.Arn}/invocations" - } - }, - "security": [], - "responses": {} - } - }, - "/ApiKeyTrue": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - }, - "/ApiKeyDefault": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredDefault.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + ], + "Version": "2012-10-17" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_apikey_required.json b/tests/translator/output/aws-cn/api_with_apikey_required.json index 6daf47459b..4dc775b381 100644 --- a/tests/translator/output/aws-cn/api_with_apikey_required.json +++ b/tests/translator/output/aws-cn/api_with_apikey_required.json @@ -1,7 +1,93 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyRequiredTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + }, + "/any/ApiKeyRequiredTrue": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment5fcd45e1a7": { + "Properties": { + "Description": "RestApi deployment id: 5fcd45e1a72dcd08c8b7c4381f8ab3450c0e14d7", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment5fcd45e1a7" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithApiKeyRequired": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +107,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithApiKeyRequiredRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +119,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +128,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +140,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,94 +149,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithApiKeyRequiredRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyRequiredTrue": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/ApiKeyRequiredTrue": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithoutAuthDeployment5fcd45e1a7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 5fcd45e1a72dcd08c8b7c4381f8ab3450c0e14d7", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment5fcd45e1a7" - }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_apikey_required_openapi_3.json b/tests/translator/output/aws-cn/api_with_apikey_required_openapi_3.json index 7d62907532..87b8c46899 100644 --- a/tests/translator/output/aws-cn/api_with_apikey_required_openapi_3.json +++ b/tests/translator/output/aws-cn/api_with_apikey_required_openapi_3.json @@ -1,7 +1,94 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/ApiKeyRequiredTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + }, + "/any/ApiKeyRequiredTrue": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment51b7925214": { + "Properties": { + "Description": "RestApi deployment id: 51b79252148f5047ff4fbaf5ac3d5e58261cc67f", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment51b7925214" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithApiKeyRequired": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +108,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithApiKeyRequiredRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +120,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +129,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +141,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,95 +150,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithApiKeyRequiredRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyRequiredTrue": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/ApiKeyRequiredTrue": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithoutAuthDeployment51b7925214": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 51b79252148f5047ff4fbaf5ac3d5e58261cc67f", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - } - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment51b7925214" + ], + "Version": "2012-10-17" }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_apikey_source.json b/tests/translator/output/aws-cn/api_with_apikey_source.json index 82ba813b17..de15eea5c5 100644 --- a/tests/translator/output/aws-cn/api_with_apikey_source.json +++ b/tests/translator/output/aws-cn/api_with_apikey_source.json @@ -1,87 +1,77 @@ { "Resources": { - "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredTrue" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", - { - "__ApiId__": { - "Ref": "MyApiWithAuthSource" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithAuthSource": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "ApiKeySourceType": "AUTHORIZER", "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/ApiKeyTrue": { "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "api_key": { - "type": "apiKey", + "in": "header", "name": "x-api-key", - "in": "header" + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] }, - "ApiKeySourceType": "AUTHORIZER" - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithAuthSourceDeployment3ffbb73485": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 3ffbb734857a2cb9c3133fc57da60c4ea2a162c1", "RestApiId": { "Ref": "MyApiWithAuthSource" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAuthSourceProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAuthSourceDeployment3ffbb73485" + }, + "RestApiId": { + "Ref": "MyApiWithAuthSource" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyFunctionWithApiKeyRequiredTrue": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -101,25 +91,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithAuthSourceProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAuthSourceDeployment3ffbb73485" - }, - "RestApiId": { - "Ref": "MyApiWithAuthSource" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredTrue" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", + { + "__ApiId__": { + "Ref": "MyApiWithAuthSource" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredTrueRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -132,7 +130,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -143,7 +142,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_auth_all_maximum.json b/tests/translator/output/aws-cn/api_with_auth_all_maximum.json index b88e837fb7..f984dd7b94 100644 --- a/tests/translator/output/aws-cn/api_with_auth_all_maximum.json +++ b/tests/translator/output/aws-cn/api_with_auth_all_maximum.json @@ -1,331 +1,17 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { @@ -334,150 +20,156 @@ { "api_key": [] } - ] - } - }, - "/any/noauth": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/cognitomultiple": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/users": { - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/default": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyCognitoAuth": [] }, { "api_key": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdarequest": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - }, - "patch": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatoken": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + "MyLambdaTokenAuth": [] }, { "api_key": [] } - ] - }, - "delete": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatokennone": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] }, { "api_key": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/noauth": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuth": [] + "NONE": [] }, { "api_key": [] } - ] - } - }, - "/any/cognitomultiple": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/users": { + "delete": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - } - }, - "/any/lambdatoken": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "get": { "responses": {}, "security": [ { @@ -486,18 +178,16 @@ { "api_key": [] } - ] - } - }, - "/any/lambdatokennone": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "patch": { "responses": {}, "security": [ { @@ -506,38 +196,34 @@ { "api_key": [] } - ] - } - }, - "/any/lambdarequest": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/any/default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { @@ -546,45 +232,52 @@ { "api_key": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "MyAuthorizationHeader", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "MyAuthorizationHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", + "identityValidationExpression": "myauthvalidationexpression", "providerARNs": [ "arn:aws:1" ], - "identityValidationExpression": "myauthvalidationexpression" - } + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, "MyCognitoAuthMultipleUserPools": { - "type": "apiKey", - "name": "MyAuthorizationHeader2", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "MyAuthorizationHeader2", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", + "identityValidationExpression": "myauthvalidationexpression2", "providerARNs": [ "arn:aws:2", "arn:aws:3" ], - "identityValidationExpression": "myauthvalidationexpression2" - } + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "MyCustomAuthHeader", + "MyLambdaRequestAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -593,18 +286,18 @@ } ] }, - "authorizerResultTtlInSeconds": 20, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - } + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "type": "apiKey", - "name": "Authorization", + "MyLambdaTokenAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -613,16 +306,17 @@ } ] }, - "authorizerResultTtlInSeconds": 0 - } + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuthNoneFunctionInvokeRole": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -631,103 +325,409 @@ } ] }, - "authorizerResultTtlInSeconds": 0, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4" + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment871773b7c8": { + "Properties": { + "Description": "RestApi deployment id: 871773b7c8b2767ed6c1ed3908f8bb97cbf343a4", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment871773b7c8" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment871773b7c8": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 871773b7c8b2767ed6c1ed3908f8bb97cbf343a4", - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithDefaultAuthorizerPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment871773b7c8" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "RestApiId": { - "Ref": "MyApi" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_auth_all_maximum_openapi_3.json b/tests/translator/output/aws-cn/api_with_auth_all_maximum_openapi_3.json index aa3463d3fc..425ef7139e 100644 --- a/tests/translator/output/aws-cn/api_with_auth_all_maximum_openapi_3.json +++ b/tests/translator/output/aws-cn/api_with_auth_all_maximum_openapi_3.json @@ -1,330 +1,112 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApi": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", - { - "__ApiId__": { - "Ref": "MyApi" + "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { @@ -333,150 +115,156 @@ { "api_key": [] } - ] - } - }, - "/any/noauth": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/cognitomultiple": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/users": { - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/default": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyCognitoAuth": [] }, { "api_key": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdarequest": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - }, - "patch": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatoken": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + "MyLambdaTokenAuth": [] }, { "api_key": [] } - ] - }, - "delete": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatokennone": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] }, { "api_key": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/noauth": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuth": [] + "NONE": [] }, { "api_key": [] } - ] - } - }, - "/any/cognitomultiple": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/users": { + "delete": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - } - }, - "/any/lambdatoken": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "get": { "responses": {}, "security": [ { @@ -485,18 +273,16 @@ { "api_key": [] } - ] - } - }, - "/any/lambdatokennone": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "patch": { "responses": {}, "security": [ { @@ -505,38 +291,34 @@ { "api_key": [] } - ] - } - }, - "/any/lambdarequest": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/any/default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { @@ -545,190 +327,408 @@ { "api_key": [] } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment47e57a77cb": { + "Properties": { + "Description": "RestApi deployment id: 47e57a77cb90238a47075df80fea7b8c6c1306e0", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment47e57a77cb" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "MyAuthorizationHeader", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - "arn:aws:1" - ], - "identityValidationExpression": "myauthvalidationexpression" - } - }, - "MyCognitoAuthMultipleUserPools": { - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "identityValidationExpression": "myauthvalidationexpression2" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "MyCustomAuthHeader", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 20, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 0 - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 0, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + { + "__ApiId__": { + "Ref": "MyApi" }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } + "__Stage__": "*" } - } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment47e57a77cb": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 47e57a77cb90238a47075df80fea7b8c6c1306e0", - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment47e57a77cb" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "RestApiId": { - "Ref": "MyApi" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_auth_all_minimum.json b/tests/translator/output/aws-cn/api_with_auth_all_minimum.json index b90828c4a3..62a93ef306 100644 --- a/tests/translator/output/aws-cn/api_with_auth_all_minimum.json +++ b/tests/translator/output/aws-cn/api_with_auth_all_minimum.json @@ -1,57 +1,55 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { + "/any/cognito": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { + "responses": {}, "security": [ { "MyCognitoAuth": [] } ], - "responses": {} - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -65,7 +63,8 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -75,96 +74,82 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithNotCachedLambdaRequestAuthDeployment234e92eab4": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiWithCognitoAuthDeployment5d6fbaaea5": { "Properties": { + "Description": "RestApi deployment id: 5d6fbaaea5286fd32d64239db8b7f2247cb3f2b5", "RestApiId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" }, - "Description": "RestApi deployment id: 234e92eab4e4c590ad261ddd55775c1edcc2972f", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiWithCognitoAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment5d6fbaaea5" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/any/lambda-request": { "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-request": { + "get": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } ], - "responses": {} - } - }, - "/lambda-request": { - "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyLambdaRequestAuth": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -177,11 +162,14 @@ } } ] - } + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -191,186 +179,105 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", + "MyApiWithLambdaRequestAuthDeployment12aa7114ad": { "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } + "Description": "RestApi deployment id: 12aa7114ad8cd8aaeffd832e49f6f8aa8b6c2062", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" }, - "Schema": [ - { - "AttributeDataType": "String", - "Required": false, - "Name": "email" - } - ] - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { "Fn::GetAtt": [ - "MyAuthFnRole", + "MyAuthFn", "Arn" ] }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } } ] } - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment5d6fbaaea5" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithNotCachedLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithLambdaRequestAuthProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuthDeployment234e92eab4" + "Ref": "MyApiWithLambdaRequestAuthDeployment12aa7114ad" }, "RestApiId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" + "Ref": "MyApiWithLambdaRequestAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithNotCachedLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaTokenAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/not-cached-lambda-request": { - "get": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuth": [] } ], - "responses": {} + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { + "MyLambdaTokenAuth": { "in": "header", + "name": "Authorization", "type": "apiKey", - "name": "Unused", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -383,11 +290,13 @@ } } ] - } + }, + "type": "token" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -397,179 +306,89 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithLambdaTokenAuthDeployment79a03805ba": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 79a03805ba3abc1f005e1282f19bb79af68b4f96", "RestApiId": { "Ref": "MyApiWithLambdaTokenAuth" }, - "Description": "RestApi deployment id: 79a03805ba3abc1f005e1282f19bb79af68b4f96", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFn" + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment79a03805ba" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithNotCachedLambdaRequestAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { + "/not-cached-lambda-request": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] } ], - "responses": {} - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaTokenAuth": { + "MyLambdaRequestAuth": { "in": "header", + "name": "Unused", "type": "apiKey", - "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -582,11 +401,13 @@ } } ] - } + }, + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -596,31 +417,29 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithNotCachedLambdaRequestAuthDeployment234e92eab4": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment12aa7114ad" - }, + "Description": "RestApi deployment id: 234e92eab4e4c590ad261ddd55775c1edcc2972f", "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithNotCachedLambdaRequestAuth" }, - "StageName": "Prod" - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithNotCachedLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ "MyAuthFn", "Arn" ] }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", @@ -631,44 +450,47 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFnLambdaNotCachedRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithNotCachedLambdaRequestAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "DeploymentId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuthDeployment234e92eab4" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-cached-lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaRequestAuthDeployment12aa7114ad": { - "Type": "AWS::ApiGateway::Deployment", + "MyAuthFn": { "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "Description": "RestApi deployment id: 12aa7114ad8cd8aaeffd832e49f6f8aa8b6c2062", - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -681,49 +503,28 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment79a03805ba" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "StageName": "Prod" - } - }, - "MyApiWithCognitoAuthDeployment5d6fbaaea5": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 5d6fbaaea5286fd32d64239db8b7f2247cb3f2b5", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "MyFn": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFnRole", @@ -733,11 +534,210 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaNotCachedRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-cached-lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_auth_all_minimum_openapi.json b/tests/translator/output/aws-cn/api_with_auth_all_minimum_openapi.json index 80863fcc9b..529f3f14bf 100644 --- a/tests/translator/output/aws-cn/api_with_auth_all_minimum_openapi.json +++ b/tests/translator/output/aws-cn/api_with_auth_all_minimum_openapi.json @@ -1,348 +1,94 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucketname", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucketname", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/cognito": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "/any/cognito": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyCognitoAuth": [] - } - ] - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - { - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - } - ] + } + } + } + }, + "/cognito": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } } } } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeployment7466d476a3": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 7466d476a34b78d8e06a6be03de27e8b5cd75bba", "RestApiId": { "Ref": "MyApiWithCognitoAuth" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeployment7466d476a3" @@ -351,64 +97,148 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/lambda-token": { - "get": { + "/any/lambda-request": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-request": { + "get": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] } - ] - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {}, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ] + } } } - }, - "openapi": "3.0.1", + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeployment6651bb8922": { + "Properties": { + "Description": "RestApi deployment id: 6651bb8922689747e94c85fa151a7800dea15b1d", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment6651bb8922" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { "components": { "securitySchemes": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -421,194 +251,364 @@ } } ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } } } } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithLambdaTokenAuthDeploymenta1cc16b088": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: a1cc16b088e0bb4f73733d3ee6a6a33e9e96f47b", "RestApiId": { "Ref": "MyApiWithLambdaTokenAuth" } - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeploymenta1cc16b088" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucketname", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFn": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeploymenta1cc16b088" + "Code": { + "S3Bucket": "bucketname", + "S3Key": "thumbnails.zip" }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnCognitoPermissionProd": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - }, - "/any/lambda-request": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeployment6651bb8922": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 6651bb8922689747e94c85fa151a7800dea15b1d", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment6651bb8922" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_auth_and_conditions_all_max.json b/tests/translator/output/aws-cn/api_with_auth_and_conditions_all_max.json index 2e0e8352d3..d221564222 100644 --- a/tests/translator/output/aws-cn/api_with_auth_and_conditions_all_max.json +++ b/tests/translator/output/aws-cn/api_with_auth_and_conditions_all_max.json @@ -2,335 +2,283 @@ "Conditions": { "PathCondition": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentfcb8b173a9" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, - "MyApiDeploymentfcb8b173a9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: fcb8b173a913f4b3a03025dc7c0b11cb18ad0e04", - "StageName": "Stage" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "NONE": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } } - }, + }, "/users": { - "put": { + "delete": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, + }, + "get": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + }, "patch": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, + }, "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "MyCognitoAuthMultipleUserPools": [] } - ], - "responses": {} - }, - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} - }, - "delete": { + } + }, + "put": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", + "identityValidationExpression": "myauthvalidationexpression", "providerARNs": [ "arn:aws:1" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - } - }, + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, + }, + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentfcb8b173a9": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Description": "RestApi deployment id: fcb8b173a913f4b3a03025dc7c0b11cb18ad0e04", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { "Ref": "MyApi" @@ -338,241 +286,293 @@ } ] } - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentfcb8b173a9" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "MyFunctionWithConditional": { + "Condition": "PathCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithConditionalRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithConditionalRole": { + "Condition": "PathCondition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionWithConditionalWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithConditionalWithDefaultAuthorizerPermissionProd": { + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionWithConditional" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionWithConditionalWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionWithConditional" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithConditionalWithLambdaTokenAuthorizerPermissionProd": { + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithConditional" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithConditionalWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionWithConditional" - }, + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyFunctionWithConditionalRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyFunctionWithConditional": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithConditionalRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "PathCondition" + }, + "Type": "AWS::Lambda::Permission" } } } diff --git a/tests/translator/output/aws-cn/api_with_auth_no_default.json b/tests/translator/output/aws-cn/api_with_auth_no_default.json index ee39a94de8..04807009e7 100644 --- a/tests/translator/output/aws-cn/api_with_auth_no_default.json +++ b/tests/translator/output/aws-cn/api_with_auth_no_default.json @@ -1,303 +1,46 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { + "/any/cognito": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + "/cognito": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -305,33 +48,36 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeploymentaa41464509": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: aa414645093f59df9e1d0461c5d796a1f6bf91a3", "RestApiId": { "Ref": "MyApiWithCognitoAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeploymentaa41464509" @@ -340,53 +86,168 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { - "get": { + "/any/lambda-request": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { + "httpMethod": "POST", "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-request": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } + } + } + } + }, + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] }, - "responses": {} + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeploymenta717d330fe": { + "Properties": { + "Description": "RestApi deployment id: a717d330fee14ce75f148c4fbf2c3dd4d6a1acf1", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeploymenta717d330fe" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, + "version": "1.0" + }, + "paths": { "/any/lambda-token": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { + "httpMethod": "POST", "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -399,183 +260,322 @@ } } ] - } + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaTokenAuthDeployment1e1bd59275": { + "Properties": { + "Description": "RestApi deployment id: 1e1bd59275be76c79386a22ea0f5104f317785b2", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment1e1bd59275" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthDeployment1e1bd59275": { - "Type": "AWS::ApiGateway::Deployment", + "MyFn": { "Properties": { - "Description": "RestApi deployment id: 1e1bd59275be76c79386a22ea0f5104f317785b2", - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment1e1bd59275" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any/lambda-request": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "securityDefinitions": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeploymenta717d330fe": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "Description": "RestApi deployment id: a717d330fee14ce75f148c4fbf2c3dd4d6a1acf1", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeploymenta717d330fe" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_auth_with_default_scopes.json b/tests/translator/output/aws-cn/api_with_auth_with_default_scopes.json index 71565997a3..a6110539fb 100644 --- a/tests/translator/output/aws-cn/api_with_auth_with_default_scopes.json +++ b/tests/translator/output/aws-cn/api_with_auth_with_default_scopes.json @@ -1,407 +1,407 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/cognitowithauthnone": { + "/cognitoauthorizercopesoverwritten": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [] + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [] + "MyCognitoAuthWithDefaultScopes": [] } - ], - "responses": {} - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" ] } - ], - "responses": {} - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] + "MyDefaultCognitoAuth": [] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": {}, "security": [ { "MyDefaultCognitoAuth": [ - "overwritten.read", + "overwritten.read", "overwritten.write" ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - ], - "responses": {} + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ "arn:aws:2" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ "arn:aws:1" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFnCognitoDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeploymentcddf4840d1": { + "Properties": { + "Description": "RestApi deployment id: cddf4840d137b720341f7a44922956a392747061", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeploymentcddf4840d1" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthDeploymentcddf4840d1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: cddf4840d137b720341f7a44922956a392747061", - "StageName": "Stage" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFnCognitoDefaultScopesDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoWithAuthNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeploymentcddf4840d1" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoWithAuthNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_auth_with_default_scopes_openapi.json b/tests/translator/output/aws-cn/api_with_auth_with_default_scopes_openapi.json index 29382f090e..fa50738646 100644 --- a/tests/translator/output/aws-cn/api_with_auth_with_default_scopes_openapi.json +++ b/tests/translator/output/aws-cn/api_with_auth_with_default_scopes_openapi.json @@ -1,408 +1,408 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuthWithDefaultScopes": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:2" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyDefaultCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/cognitowithauthnone": { + "/cognitoauthorizercopesoverwritten": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [] + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [] + "MyCognitoAuthWithDefaultScopes": [] } - ], - "responses": {} - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" ] } - ], - "responses": {} - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] + "MyDefaultCognitoAuth": [] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": {}, "security": [ { "MyDefaultCognitoAuth": [ - "overwritten.read", + "overwritten.read", "overwritten.write" ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] + "NONE": [] } - ], - "responses": {} - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:2" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFnCognitoDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeployment815f0fba0e": { + "Properties": { + "Description": "RestApi deployment id: 815f0fba0e3496a1f5576f705305124b291b7c03", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment815f0fba0e" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFnCognitoDefaultScopesDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthDeployment815f0fba0e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 815f0fba0e3496a1f5576f705305124b291b7c03" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoWithAuthNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment815f0fba0e" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoWithAuthNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_aws_account_blacklist.json b/tests/translator/output/aws-cn/api_with_aws_account_blacklist.json index 7d6b087798..8074dbc809 100644 --- a/tests/translator/output/aws-cn/api_with_aws_account_blacklist.json +++ b/tests/translator/output/aws-cn/api_with_aws_account_blacklist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionAnyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,85 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -146,16 +149,16 @@ } ] } - ], + ] + }, + { + "Action": "execute-api:Invoke", + "Effect": "Deny", "Principal": { "AWS": [ "12345" ] - } - }, - { - "Effect": "Deny", - "Action": "execute-api:Invoke", + }, "Resource": [ { "Fn::Sub": [ @@ -165,38 +168,34 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentfed6286f35": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: fed6286f35e2d221984f3f4ece0897e385efadd0", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentfed6286f35" @@ -205,7 +204,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_aws_account_whitelist.json b/tests/translator/output/aws-cn/api_with_aws_account_whitelist.json index 203ccc9044..70c6ae51bb 100644 --- a/tests/translator/output/aws-cn/api_with_aws_account_whitelist.json +++ b/tests/translator/output/aws-cn/api_with_aws_account_whitelist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionAnyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,85 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -146,16 +149,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "67890" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -165,16 +168,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "67890" - ] - } + ] }, { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -184,16 +187,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "67890" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -203,38 +206,34 @@ } ] } - ], - "Principal": { - "AWS": [ - "67890" - ] - } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment41ca369f74": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 41ca369f74fd0e0dd14c28e4db79e04494fb926a", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment41ca369f74" @@ -243,7 +242,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_aws_iam_auth_overrides.json b/tests/translator/output/aws-cn/api_with_aws_iam_auth_overrides.json index 4636278e7e..1f148b7e00 100644 --- a/tests/translator/output/aws-cn/api_with_aws_iam_auth_overrides.json +++ b/tests/translator/output/aws-cn/api_with_aws_iam_auth_overrides.json @@ -1,945 +1,945 @@ { "Resources": { - "MyFunctionCustomInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionCustomInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionNoneAuth": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionNoneAuthRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionNullInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionNullInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeployment4253f994cd" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } - }, - "MyApiWithAwsIamAuthDeployment4253f994cd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "Description": "RestApi deployment id: 4253f994cdaf14767907decd5cb875cbafc08704", - "StageName": "Stage" - } - }, - "MyFunctionWithoutAuthRole": { - "Type": "AWS::IAM::Role", + "MyApiWithAwsIamAuth": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/MyFunctionCustomInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::456::role/something-else", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCustomInvokeRole.Arn}/invocations" + } + } } - } - ] - } - } - }, - "MyFunctionCustomInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionCustomInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionCustomInvokeRole", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + }, + "/MyFunctionDefaultInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionDefaultInvokeRole.Arn}/invocations" + } + } } - } - ] - } - } - }, - "MyFunctionMyCognitoAuthAPI1PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionMyCognitoAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionMyCognitoAuth", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + }, + "/MyFunctionMyCognitoAuth": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionMyCognitoAuth.Arn}/invocations" + } + } + } + }, + "/MyFunctionNONEInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNONEInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionNoneAuth": { + "get": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoneAuth.Arn}/invocations" + } + } + } + }, + "/MyFunctionNullInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNullInvokeRole.Arn}/invocations" + } + } } + }, + "/MyFunctionWithoutAuth": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::123:role/AUTH_AWS_IAM", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithoutAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + }, + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:cognito-idp:xxxxxxxxx" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyApiWithAwsIamAuthNoCallerCredentialsDeployment07ee28f86e": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthDeployment4253f994cd": { "Properties": { + "Description": "RestApi deployment id: 4253f994cdaf14767907decd5cb875cbafc08704", "RestApiId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - }, - "Description": "RestApi deployment id: 07ee28f86edc705d064d88266db4dea8f5c305b1", + "Ref": "MyApiWithAwsIamAuth" + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiWithAwsIamAuthNoCallerCredentials": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoCallerCredentials.Arn}/invocations" - } - }, + "get": { + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} - }, - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCallerCredentialsOverride.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + } + } + }, + "post": { + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoCallerCredentials.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFunctionWithoutAuthAPI2PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthNoCallerCredentialsDeployment07ee28f86e": { + "Properties": { + "Description": "RestApi deployment id: 07ee28f86edc705d064d88266db4dea8f5c305b1", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthNoCallerCredentialsProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentialsDeployment07ee28f86e" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeployment4253f994cd" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionCallerCredentialsOverride": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionCallerCredentialsOverrideRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionCallerCredentialsOverrideAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionWithoutAuth" - }, + "Ref": "MyFunctionCallerCredentialsOverride" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionWithoutAuth", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionDefaultInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionCallerCredentialsOverrideRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionDefaultInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionDefaultInvokeRole", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - ] - } - } - }, - "MyFunctionMyCognitoAuth": { - "Type": "AWS::Lambda::Function", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionCustomInvokeRole": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionMyCognitoAuthRole", + "MyFunctionCustomInvokeRoleRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRoleRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionCustomInvokeRoleAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionCustomInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionCustomInvokeRole", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionCustomInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionNONEInvokeRole": { - "Type": "AWS::Lambda::Function", + "MyFunctionDefaultInvokeRole": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNONEInvokeRoleRole", + "MyFunctionDefaultInvokeRoleRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoCallerCredentialsAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionDefaultInvokeRoleAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNoCallerCredentials" - }, + "Ref": "MyFunctionDefaultInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionDefaultInvokeRole", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - } + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNoneAuthRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionDefaultInvokeRoleRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionMyCognitoAuth": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionMyCognitoAuthRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionMyCognitoAuthAPI1PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionMyCognitoAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionMyCognitoAuth", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionMyCognitoAuthRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionCustomInvokeRoleRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNONEInvokeRole": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNONEInvokeRoleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNONEInvokeRoleAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionNONEInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNONEInvokeRole", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNONEInvokeRoleRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNoCallerCredentials": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNoCallerCredentialsRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionCallerCredentialsOverrideAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionNoCallerCredentialsAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionCallerCredentialsOverride" - }, + "Ref": "MyFunctionNoCallerCredentials" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNoCallerCredentialsRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - ] - } - } - }, - "MyFunctionCallerCredentialsOverride": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionCallerCredentialsOverrideRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionWithoutAuth": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNoneAuth": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionWithoutAuthRole", + "MyFunctionNoneAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionNullInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNullInvokeRole", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } - } - ] - } - } - }, - "MyFunctionNONEInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNoneAuthAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNONEInvokeRole" - }, + "Ref": "MyFunctionNoneAuth" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNONEInvokeRole", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNoneAuth", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNoCallerCredentialsRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNoneAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionDefaultInvokeRoleRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionCallerCredentialsOverrideRole": { - "Type": "AWS::IAM::Role", + "MyFunctionNullInvokeRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNullInvokeRoleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNullInvokeRoleAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionNullInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNullInvokeRole", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionMyCognitoAuthRole": { - "Type": "AWS::IAM::Role", + "MyFunctionNullInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyApiWithAwsIamAuthNoCallerCredentialsProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentialsDeployment07ee28f86e" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - }, - "StageName": "Prod" - } - }, - "MyFunctionDefaultInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionDefaultInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoCallerCredentials": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithoutAuth": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNoCallerCredentialsRole", + "MyFunctionWithoutAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/MyFunctionWithoutAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithoutAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNONEInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNONEInvokeRole.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionMyCognitoAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionMyCognitoAuth.Arn}/invocations" - } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } - }, - "/MyFunctionDefaultInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionDefaultInvokeRole.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionCustomInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCustomInvokeRole.Arn}/invocations" - }, - "credentials": "arn:aws:iam::456::role/something-else" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNullInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNullInvokeRole.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNoneAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoneAuth.Arn}/invocations" - } - }, - "security": [ - { - "NONE": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:cognito-idp:xxxxxxxxx" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyFunctionNoneAuthAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithoutAuthAPI2PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNoneAuth" - }, + "Ref": "MyFunctionWithoutAuth" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNoneAuth", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionWithoutAuth", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNONEInvokeRoleRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithoutAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_basic_custom_domain.json b/tests/translator/output/aws-cn/api_with_basic_custom_domain.json index 88e64e6a83..1935c13806 100644 --- a/tests/translator/output/aws-cn/api_with_basic_custom_domain.json +++ b/tests/translator/output/aws-cn/api_with_basic_custom_domain.json @@ -1,421 +1,421 @@ { "Parameters": { - "MyDomainName": { - "Default": "another-example.com", - "Type": "String" - }, "MyDomainCert": { - "Default": "another-api-arn", + "Default": "another-api-arn", + "Type": "String" + }, + "MyDomainName": { + "Default": "another-example.com", "Type": "String" } - }, + }, "Resources": { + "ApiGatewayDomainName23cdccdf9c": { + "Properties": { + "CertificateArn": "my-api-cert-arn", + "DomainName": "api-example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + }, + "MutualTlsAuthentication": { + "TruststoreUri": "my-api-truststore-uri", + "TruststoreVersion": "my-api-truststore-version" + }, + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "ApiGatewayDomainNameeab65c1531": { + "Properties": { + "DomainName": "another-example.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "RegionalCertificateArn": "another-api-arn" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyAnotherApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/another/get": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyAnotherApiBasePathMapping": { + "Properties": { + "DomainName": { + "Ref": "ApiGatewayDomainNameeab65c1531" + }, + "RestApiId": { + "Ref": "MyAnotherApi" + }, + "Stage": { + "Ref": "MyAnotherApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyAnotherApiDeployment989ae20f23": { + "Properties": { + "Description": "RestApi deployment id: 989ae20f23c53c333389afc4e570683e5665c797", + "RestApiId": { + "Ref": "MyAnotherApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyAnotherApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyAnotherApiDeployment989ae20f23" + }, + "RestApiId": { + "Ref": "MyAnotherApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + }, + "/get": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment92d6d51a5e": { + "Properties": { + "Description": "RestApi deployment id: 92d6d51a5e324a2836c79d3645d7e678f063037e", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment92d6d51a5e" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApifetchBasePathMapping": { + "Properties": { + "BasePath": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainName23cdccdf9c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApigetBasePathMapping": { + "Properties": { + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainName23cdccdf9c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionAnotherGetPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/another/get", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/another/get", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyAnotherApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment92d6d51a5e" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, - "MyFunctionImplicitGetPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionApiPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", { - "__Stage__": "*", "__ApiId__": { - "Ref": "ServerlessRestApi" - } + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } - }, - "MyAnotherApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyAnotherApiDeployment989ae20f23" - }, - "RestApiId": { - "Ref": "MyAnotherApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyAnotherApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitGetPermissionProd": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/another/get": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } - }, - "openapi": "3.0.1" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyApifetchBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "fetch", - "DomainName": { - "Ref": "ApiGatewayDomainName23cdccdf9c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApigetBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "get", - "DomainName": { - "Ref": "ApiGatewayDomainName23cdccdf9c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessRestApi": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/get": { - "put": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/fetch": { + "/implicit": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0.1" - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyAnotherApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainNameeab65c1531" - }, - "RestApiId": { - "Ref": "MyAnotherApi" - }, - "Stage": { - "Ref": "MyAnotherApiProdStage" - } - } - }, - "ApiGatewayDomainNameeab65c1531": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "RegionalCertificateArn": "another-api-arn", - "DomainName": "another-example.com" - } - }, - "ApiGatewayDomainName23cdccdf9c": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "my-api-cert-arn", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "MutualTlsAuthentication": { - "TruststoreUri": "my-api-truststore-uri", - "TruststoreVersion": "my-api-truststore-version" - }, - "SecurityPolicy": "TLS_1_2", - "DomainName": "api-example.com" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment6aef2b756e" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "MyApiDeployment92d6d51a5e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 92d6d51a5e324a2836c79d3645d7e678f063037e" - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ServerlessRestApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainNameeab65c1531" - }, + }, "RestApiId": { "Ref": "ServerlessRestApi" - }, + }, "Stage": { "Ref": "ServerlessRestApiProdStage" } - } - }, + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "ServerlessRestApiDeployment6aef2b756e": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 6aef2b756ee814f8722e71ca5e3f0d187e05aed5", "RestApiId": { "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 6aef2b756ee814f8722e71ca5e3f0d187e05aed5", + }, "StageName": "Stage" - } - }, - "MyAnotherApiDeployment989ae20f23": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment6aef2b756e" + }, "RestApiId": { - "Ref": "MyAnotherApi" - }, - "Description": "RestApi deployment id: 989ae20f23c53c333389afc4e570683e5665c797" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/implicit": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_basic_custom_domain_http.json b/tests/translator/output/aws-cn/api_with_basic_custom_domain_http.json index 72b8198b21..dfabf3b033 100644 --- a/tests/translator/output/aws-cn/api_with_basic_custom_domain_http.json +++ b/tests/translator/output/aws-cn/api_with_basic_custom_domain_http.json @@ -1,37 +1,21 @@ { "Parameters": { - "MyDomainName": { - "Default": "sam-example.com", - "Type": "String" - }, "MyDomainCert": { - "Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "Type": "String" + }, + "MyDomainName": { + "Default": "sam-example.com", "Type": "String" } - }, + }, "Resources": { - "MyApibasicApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV22dbf35af54" - }, - "ApiMappingKey": "basic", - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, "ApiGatewayDomainNameV22dbf35af54": { - "Type": "AWS::ApiGatewayV2::DomainName", "Properties": { - "DomainName": "sam-example.com", + "DomainName": "sam-example.com", "DomainNameConfigurations": [ { - "CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", "EndpointType": "REGIONAL", "SecurityPolicy": "TLS_1_2" } @@ -43,190 +27,206 @@ "Tags": { "httpapi:createdBy": "SAM" } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApibeginhereApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV22dbf35af54" - }, - "ApiMappingKey": "begin-here", - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RecordSetGroup1f4f569a7e": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { "Properties": { - "HostedZoneName": "sam-example.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV22dbf35af54", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV22dbf35af54", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "sam-example.com" - } - ] - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + } + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/basic": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], + }, "servers": [ { "x-amazon-apigateway-endpoint-configuration": { "disableExecuteApiEndpoint": true } } + ], + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApibasicApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "basic", + "DomainName": { + "Ref": "ApiGatewayDomainNameV22dbf35af54" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApibeginhereApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "begin-here", + "DomainName": { + "Ref": "ApiGatewayDomainNameV22dbf35af54" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "RecordSetGroup1f4f569a7e": { + "Properties": { + "HostedZoneName": "sam-example.com.", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV22dbf35af54", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV22dbf35af54", + "RegionalHostedZoneId" + ] + } + }, + "Name": "sam-example.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics.json b/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics.json index a7c6e267e5..2305750398 100644 --- a/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics.json +++ b/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics.json @@ -2,18 +2,18 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { - "MyDomainCert": { - "Default": "another-api-arn", - "Type": "String" - }, "EndpointConf": { - "Default": "REGIONAL", + "Default": "REGIONAL", + "Type": "String" + }, + "MyDomainCert": { + "Default": "another-api-arn", "Type": "String" }, "MyMTLSUri": { @@ -24,326 +24,326 @@ "Default": "another-api-truststore-version", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "C1" - }, - "MyFunctionImplicitGetPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "C1" - }, - "MyApifetchBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayDomainNamec0cd2d9dfc": { + "Condition": "C1", "Properties": { - "BasePath": "fetch", "DomainName": { - "Ref": "ApiGatewayDomainNamec0cd2d9dfc" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "MyApiDeployment4f2c19d290": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 4f2c19d290875d88d8e30124f0953f1784e1b54d" - }, - "Condition": "C1" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment599c0b434d" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "C1" - }, - "ServerlessRestApiDeployment599c0b434d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 599c0b434d7122049846aedc74269bb6020bd9d3", - "StageName": "Stage" - }, - "Condition": "C1" - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Fn::Sub": "example-cn-north-1.com" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "C1" - }, - "MyApigetBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "get", - "DomainName": { - "Ref": "ApiGatewayDomainNamec0cd2d9dfc" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, + }, + "MutualTlsAuthentication": { + "TruststoreUri": "another-api-truststore-uri", + "TruststoreVersion": "another-api-truststore-version" + }, + "RegionalCertificateArn": "another-api-arn", + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "/get": { "Fn::If": [ - "C1", + "C1", { "put": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1" - }, + } + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment4f2c19d290": { + "Condition": "C1", + "Properties": { + "Description": "RestApi deployment id: 4f2c19d290875d88d8e30124f0953f1784e1b54d", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Condition": "C1", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment4f2c19d290" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" - }, - "Condition": "C1" - }, - "ApiGatewayDomainNamec0cd2d9dfc": { - "Type": "AWS::ApiGateway::DomainName", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApifetchBasePathMapping": { + "Condition": "C1", "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + "BasePath": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainNamec0cd2d9dfc" }, - "MutualTlsAuthentication": { - "TruststoreUri": "another-api-truststore-uri", - "TruststoreVersion": "another-api-truststore-version" + "RestApiId": { + "Ref": "MyApi" }, - "SecurityPolicy": "TLS_1_2", - "RegionalCertificateArn": "another-api-arn", + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApigetBasePathMapping": { + "Condition": "C1", + "Properties": { + "BasePath": "get", "DomainName": { - "Fn::Sub": "example-cn-north-1.com" + "Ref": "ApiGatewayDomainNamec0cd2d9dfc" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { + "Condition": "C1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitGetPermissionProd": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Condition": "C1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/implicit": { "Fn::If": [ - "C1", + "C1", { "post": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, - "Condition": "C1" - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment599c0b434d": { + "Condition": "C1", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "C1" + "Description": "RestApi deployment id: 599c0b434d7122049846aedc74269bb6020bd9d3", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment599c0b434d" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics_http.json b/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics_http.json index c0df26d42d..61d3d9bc03 100644 --- a/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics_http.json +++ b/tests/translator/output/aws-cn/api_with_basic_custom_domain_intrinsics_http.json @@ -2,18 +2,18 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { - "MyDomainCert": { - "Default": "another-api-arn", - "Type": "String" - }, "EndpointConf": { - "Default": "REGIONAL", + "Default": "REGIONAL", + "Type": "String" + }, + "MyDomainCert": { + "Default": "another-api-arn", "Type": "String" }, "MyMTLSUriHTTP": { @@ -24,315 +24,315 @@ "Default": "another-api-v2-truststore-version", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV2c0cd2d9dfc": { + "Condition": "C1", "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": { + "Fn::Sub": "example-cn-north-1.com" + }, + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "another-api-arn", + "EndpointType": "REGIONAL", + "SecurityPolicy": "TLS_1_2" } - ] - }, - "Condition": "C1" - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", + ], + "MutualTlsAuthentication": { + "TruststoreUri": "another-api-v2-truststore-uri", + "TruststoreVersion": "another-api-v2-truststore-version" + }, "Tags": { "httpapi:createdBy": "SAM" } - }, - "Condition": "C1" - }, - "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/implicit": { + "/get": { "Fn::If": [ - "C1", + "C1", { - "post": { + "put": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", + }, + "servers": [ + { + "x-amazon-apigateway-endpoint-configuration": { + "disableExecuteApiEndpoint": false + } + } + ], "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApifetchApiMapping": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainNameV2c0cd2d9dfc" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApigetApiMapping": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "get", + "DomainName": { + "Ref": "ApiGatewayDomainNameV2c0cd2d9dfc" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { + "Condition": "C1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermission": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionImplicitGetPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "C1", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "C1", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "C1" - }, - "ApiGatewayDomainNameV2c0cd2d9dfc": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainNameConfigurations": [ - { - "CertificateArn": "another-api-arn", - "EndpointType": "REGIONAL", - "SecurityPolicy": "TLS_1_2" - } - ], - "MutualTlsAuthentication": { - "TruststoreUri": "another-api-v2-truststore-uri", - "TruststoreVersion": "another-api-v2-truststore-version" - }, - "DomainName": { - "Fn::Sub": "example-cn-north-1.com" - }, - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "C1" - }, - "MyFunctionApiPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "C1" - }, - "MyApigetApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV2c0cd2d9dfc" - }, - "ApiMappingKey": "get", - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "C1" - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessHttpApi": { + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get": { + "/implicit": { "Fn::If": [ - "C1", + "C1", { - "put": { + "post": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ], - "servers": [ - { - "x-amazon-apigateway-endpoint-configuration": { - "disableExecuteApiEndpoint": false - } - } ] } - }, - "Condition": "C1" - }, - "MyApifetchApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Condition": "C1", "Properties": { "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV2c0cd2d9dfc" - }, - "ApiMappingKey": "fetch", - "Stage": { - "Ref": "MyApiProdStage" + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - }, - "Condition": "C1" + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_binary_media_types.json b/tests/translator/output/aws-cn/api_with_binary_media_types.json index d9703bd9ef..a480e527da 100644 --- a/tests/translator/output/aws-cn/api_with_binary_media_types.json +++ b/tests/translator/output/aws-cn/api_with_binary_media_types.json @@ -1,219 +1,219 @@ { "Parameters": { "BMT": { - "Default": "image~1jpg", + "Default": "image~1jpg", "Type": "String" } - }, + }, "Resources": { + "ExplicitApi": { + "Properties": { + "BinaryMediaTypes": [ + "image~1gif", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "application~1octet-stream", + "image~1jpg" + ], + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { "Properties": { "BinaryMediaTypes": [ - "image~1gif", + "image~1gif", { "Fn::Join": [ - "~1", + "~1", [ - "image", + "image", "png" ] ] - }, - "application~1octet-stream", - "image~1jpg" - ], - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcc75b253a7" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcc75b253a7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cc75b253a750cc6450a4de493f56a526d23b52d4", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { + } + ], "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/gif", + "image/gif", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] } ] - }, - "BinaryMediaTypes": [ - "image~1gif", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - } - ], + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcc75b253a7": { + "Properties": { + "Description": "RestApi deployment id: cc75b253a750cc6450a4de493f56a526d23b52d4", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcc75b253a7" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_binary_media_types_definition_body.json b/tests/translator/output/aws-cn/api_with_binary_media_types_definition_body.json index 75b031c547..76b75f995b 100644 --- a/tests/translator/output/aws-cn/api_with_binary_media_types_definition_body.json +++ b/tests/translator/output/aws-cn/api_with_binary_media_types_definition_body.json @@ -1,150 +1,150 @@ { "Parameters": { "BMT": { - "Default": "image~1jpeg", + "Default": "image~1jpeg", "Type": "String" } - }, + }, "Resources": { - "ExplicitApiManagedSwaggerProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2" - }, - "RestApiId": { - "Ref": "ExplicitApiManagedSwagger" - }, - "StageName": "Prod" - } - }, - "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApiManagedSwagger" - }, - "Description": "RestApi deployment id: fe9c2c09a27ce00c2fa53d5a491cf343e6a3278e", - "StageName": "Stage" - } - }, "ExplicitApiDefinitionBody": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "BinaryMediaTypes": [ + "image~1jpeg", + "image~1jpg", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "application~1json" + ], "Body": { - "paths": {}, - "swagger": "2.0", + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/jpeg", - "image/jpg", + "image/jpeg", + "image/jpg", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] - }, + }, "application/json" ] - }, - "BinaryMediaTypes": [ - "image~1jpeg", - "image~1jpg", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - }, - "application~1json" - ], + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ExplicitApiDefinitionBodyDeployment1f26996adb": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 1f26996adbe5077359ecb2bb0688a9cc0ae8e4fc", "RestApiId": { "Ref": "ExplicitApiDefinitionBody" - }, - "Description": "RestApi deployment id: 1f26996adbe5077359ecb2bb0688a9cc0ae8e4fc", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiDefinitionBodyProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDefinitionBodyDeployment1f26996adb" - }, + }, "RestApiId": { "Ref": "ExplicitApiDefinitionBody" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, "ExplicitApiManagedSwagger": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "BinaryMediaTypes": [ + "image~1jpeg", + "image~1jpg", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "image~1gif" + ], "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0", + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/jpeg", - "image/jpg", + "image/jpeg", + "image/jpg", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] - }, + }, "image/gif" ] - }, - "BinaryMediaTypes": [ - "image~1jpeg", - "image~1jpg", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - }, - "image~1gif" - ], + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2": { + "Properties": { + "Description": "RestApi deployment id: fe9c2c09a27ce00c2fa53d5a491cf343e6a3278e", + "RestApiId": { + "Ref": "ExplicitApiManagedSwagger" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiManagedSwaggerProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2" + }, + "RestApiId": { + "Ref": "ExplicitApiManagedSwagger" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_canary_setting.json b/tests/translator/output/aws-cn/api_with_canary_setting.json index 412da24e19..39ff533d9f 100644 --- a/tests/translator/output/aws-cn/api_with_canary_setting.json +++ b/tests/translator/output/aws-cn/api_with_canary_setting.json @@ -1,7 +1,53 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "CanarySetting": { + "PercentTraffic": 100, + "StageVariablesOverrides": { + "sv1": "test", + "sv2": "test2" + }, + "UseStageCache": false + }, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,161 +63,84 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ImplicitApiFunctionRole": { "Properties": { - "CanarySetting": { - "PercentTraffic": 100, - "UseStageCache": false, - "StageVariablesOverrides": { - "sv2": "test2", - "sv1": "test" - } - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "CanarySetting": { - "PercentTraffic": 100, - "UseStageCache": false, - "StageVariablesOverrides": { - "sv2": "test2", - "sv1": "test" + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcb4fb12558" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcb4fb12558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -185,7 +154,38 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcb4fb12558": { + "Properties": { + "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CanarySetting": { + "PercentTraffic": 100, + "StageVariablesOverrides": { + "sv1": "test", + "sv2": "test2" + }, + "UseStageCache": false + }, + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcb4fb12558" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_cors.json b/tests/translator/output/aws-cn/api_with_cors.json index 0abca4a3b5..e8458d3e10 100644 --- a/tests/translator/output/aws-cn/api_with_cors.json +++ b/tests/translator/output/aws-cn/api_with_cors.json @@ -1,537 +1,537 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionAnyApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment3a5a78688c": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentdb43b8746d" - }, + "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment3a5a78688c" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment3a5a78688c": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeploymentdb43b8746d": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: db43b8746d8595bef1c820446f63555bf6a6fb10", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/foo": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } + }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + } + }, + "/foo": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } } - }, - "responses": {} - } - }, - "/": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "consumes": [ - "application/json" - ], - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentdb43b8746d": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: db43b8746d8595bef1c820446f63555bf6a6fb10", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentdb43b8746d" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_cors_and_auth_no_preflight_auth.json b/tests/translator/output/aws-cn/api_with_cors_and_auth_no_preflight_auth.json index 7c24e8b012..3687890489 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_auth_no_preflight_auth.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_auth_no_preflight_auth.json @@ -1,310 +1,297 @@ { "Resources": { - "ServerlessApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - }, - "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - } - } - } - }, - "consumes": [ - "application/json" - ], - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ServerlessApiDeployment6050a96a0f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessApi" - }, - "Description": "RestApi deployment id: 6050a96a0f36baa9bc42da60f16427b8e3f34291", - "StageName": "Stage" - } - }, - "ApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessApiDeployment6050a96a0f" - }, - "RestApiId": { - "Ref": "ServerlessApi" - }, - "StageName": "Prod" - } - }, - "ApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionPostHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiFunctionRole": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyAuthFnRole", + "MyAuthFnRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + }, + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessApiDeployment6050a96a0f": { + "Properties": { + "Description": "RestApi deployment id: 6050a96a0f36baa9bc42da60f16427b8e3f34291", + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ServerlessApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { "Ref": "ServerlessApi" @@ -312,7 +299,20 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessApiDeployment6050a96a0f" + }, + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_cors_and_auth_preflight_auth.json b/tests/translator/output/aws-cn/api_with_cors_and_auth_preflight_auth.json index eb39c45cc8..ca37b45077 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_auth_preflight_auth.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_auth_preflight_auth.json @@ -1,7 +1,6 @@ { "Resources": { "ApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessApi" @@ -93,10 +62,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +74,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "ServerlessApi" @@ -114,10 +83,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -137,13 +136,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -156,7 +154,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -167,85 +166,50 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] - }, - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } } @@ -255,80 +219,112 @@ { "MyLambdaRequestAuth": [] } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] - }, + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + }, + "/any": { "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -342,45 +338,36 @@ } ] }, - "identitySource": "method.request.header.Authorization1" - } + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessApiDeployment4f438627b9": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 4f438627b99c6a82f8b37e212f35f486c5998740", "RestApiId": { "Ref": "ServerlessApi" }, "StageName": "Stage" - } - }, - "ServerlessApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessApiDeployment4f438627b9" - }, - "RestApiId": { - "Ref": "ServerlessApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -400,7 +387,20 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessApiDeployment4f438627b9" + }, + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_cors_and_conditions_no_definitionbody.json b/tests/translator/output/aws-cn/api_with_cors_and_conditions_no_definitionbody.json index fddff4ed76..4b7a9e5f02 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_conditions_no_definitionbody.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_conditions_no_definitionbody.json @@ -9,8 +9,234 @@ } }, "Resources": { - "ImplicitApiFunction2": { - "Type": "AWS::Lambda::Function", + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "delete": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction2.Arn}/invocations" + } + } + }, + "get": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'www.example.com'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "/any": { + "Fn::If": [ + "MyCondition", + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'www.example.com'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment6f2bd0dddd": { + "Properties": { + "Description": "RestApi deployment id: 6f2bd0dddd4e3f72c4ae0c49eac0238610bfb537", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment6f2bd0dddd" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Condition": "MyCondition", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,7 +245,7 @@ "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunction2Role", + "ImplicitApiFunctionRole", "Arn" ] }, @@ -30,40 +256,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunction2Role": { - "Type": "AWS::IAM::Role", + "ImplicitApiFunction2": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunction2Role", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunction2DeleteHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -81,38 +300,12 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Condition": "MyCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Condition": "MyCondition", + "ImplicitApiFunction2Role": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -125,7 +318,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -136,10 +330,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -149,7 +343,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ExplicitApi" @@ -158,10 +352,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -171,7 +365,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ExplicitApi" @@ -180,10 +374,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionPostHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -193,7 +387,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "ExplicitApi" @@ -202,233 +396,39 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { + "Condition": "MyCondition", "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "delete": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction2.Arn}/invocations" - } - }, - "responses": {} - }, - "get": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "post": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] - }, - "options": { - "summary": "CORS support", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'www.example.com'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,OPTIONS,POST'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - } - } - } } - }, - "/any": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-any-method": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "options": { - "summary": "CORS support", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'www.example.com'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - } - } - } - } - }, - { - "Ref": "AWS::NoValue" - } - ] } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment6f2bd0dddd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 6f2bd0dddd4e3f72c4ae0c49eac0238610bfb537", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment6f2bd0dddd" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json b/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json index 81a665c791..c592b000b5 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_credentials_false.json @@ -1,207 +1,207 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment398246867a" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment398246867a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment398246867a": { + "Properties": { + "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment398246867a" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_headers.json b/tests/translator/output/aws-cn/api_with_cors_and_only_headers.json index 2512bfc953..abd2af34c8 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_headers.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_headers.json @@ -1,369 +1,369 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ServerlessRestApiDeployment9467cf1cd5": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 9467cf1cd5e9d5da97f5af035e6044f12dd258cd", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment9467cf1cd5" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ExplicitApiDeployment03e65d7ea2": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 03e65d7ea2275d648803eecb7fa8e0ae7cd8f0aa", "RestApiId": { "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 03e65d7ea2275d648803eecb7fa8e0ae7cd8f0aa", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment03e65d7ea2" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ImplicitApiFunctionPostHtmlPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment03e65d7ea2" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment9467cf1cd5": { + "Properties": { + "Description": "RestApi deployment id: 9467cf1cd5e9d5da97f5af035e6044f12dd258cd", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment9467cf1cd5" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json b/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json index d778140c01..fb5f016326 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_maxage.json @@ -1,215 +1,215 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentb61cfb7d60": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: b61cfb7d602d889bbd9867dcbf0f75d3066dcc56", - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentb61cfb7d60" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Max-Age": 600, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, + "Access-Control-Allow-Origin": { + "type": "string" + }, "Access-Control-Max-Age": { "type": "integer" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Max-Age": 600 + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Max-Age": 600, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, + "Access-Control-Allow-Origin": { + "type": "string" + }, "Access-Control-Max-Age": { "type": "integer" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Max-Age": 600 + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentb61cfb7d60": { + "Properties": { + "Description": "RestApi deployment id: b61cfb7d602d889bbd9867dcbf0f75d3066dcc56", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentb61cfb7d60" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_methods.json b/tests/translator/output/aws-cn/api_with_cors_and_only_methods.json index 38ab5dd0a9..e900bd7d2c 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_methods.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_methods.json @@ -1,7 +1,6 @@ { "Resources": { "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,148 +62,178 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "methods" + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "'*'" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } } }, "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "methods" + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "'*'" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment5277de8b80": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 5277de8b80bb6b1d6d9ab9bf93f151e78629a3a4", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment5277de8b80" @@ -243,7 +242,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_cors_and_only_origins.json b/tests/translator/output/aws-cn/api_with_cors_and_only_origins.json index 3e9e0a4aba..88db95d1d4 100644 --- a/tests/translator/output/aws-cn/api_with_cors_and_only_origins.json +++ b/tests/translator/output/aws-cn/api_with_cors_and_only_origins.json @@ -1,357 +1,357 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymenta7a992bbb6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a7a992bbb604dcd7667af3caa050bf14af2bf684", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymenta7a992bbb6" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentb4ba0b8ae8" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ServerlessRestApiDeploymentb4ba0b8ae8": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta7a992bbb6": { "Properties": { + "Description": "RestApi deployment id: a7a992bbb604dcd7667af3caa050bf14af2bf684", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: b4ba0b8ae8163e6dd52040648ae4ebda76cc5d99", + "Ref": "ExplicitApi" + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymenta7a992bbb6" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentb4ba0b8ae8": { + "Properties": { + "Description": "RestApi deployment id: b4ba0b8ae8163e6dd52040648ae4ebda76cc5d99", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentb4ba0b8ae8" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_cors_no_definitionbody.json b/tests/translator/output/aws-cn/api_with_cors_no_definitionbody.json index af8f0af8f1..918acd3889 100644 --- a/tests/translator/output/aws-cn/api_with_cors_no_definitionbody.json +++ b/tests/translator/output/aws-cn/api_with_cors_no_definitionbody.json @@ -1,272 +1,155 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, - "post": { - "x-amazon-apigateway-integration": { "type": "aws_proxy", - "httpMethod": "POST", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + } + }, + "/any": { "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeployment421c84890d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 421c84890dc6500d03ebae76efaeb8f172a10c9b", "RestApiId": { "Ref": "ExplicitApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment421c84890d" @@ -275,7 +158,124 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_cors_openapi_3.json b/tests/translator/output/aws-cn/api_with_cors_openapi_3.json index e814d0d1cd..42197b0792 100644 --- a/tests/translator/output/aws-cn/api_with_cors_openapi_3.json +++ b/tests/translator/output/aws-cn/api_with_cors_openapi_3.json @@ -1,531 +1,531 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiDeployment147347629d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 147347629dc3d0f3815602132def464c995d7245" - } - }, - "ImplicitApiFunctionAnyApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment8cc53ffaa5": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment147347629d" - }, + "Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment8cc53ffaa5" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment8cc53ffaa5": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { - "/foo": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } + }, "options": { + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "schema": { + "type": "string" + } + }, + "Access-Control-Allow-Origin": { + "schema": { + "type": "string" + } + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + } + }, + "/foo": { + "options": { "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } - }, - "Access-Control-Allow-Methods": { + }, + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } - }, - "description": "Default response for CORS method" - } - } - }, - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } } - }, - "responses": {} - } - }, - "/": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - } - } - } - }, - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "schema": { - "type": "string" } - }, - "Access-Control-Allow-Methods": { - "schema": { - "type": "string" - } - } - }, - "description": "Default response for CORS method" - } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" } - }, - "get": { + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0" - }, + } + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment147347629d": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: 147347629dc3d0f3815602132def464c995d7245", + "RestApiId": { + "Ref": "ServerlessRestApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment147347629d" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53.json index 8637e03b35..58fb319963 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53.json @@ -1,205 +1,205 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { + "ApiGatewayDomainName0caaf24ab1": { + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "DomainName": "example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentfb330328f1": { + "Properties": { + "Description": "RestApi deployment id: fb330328f152e4bb4b7d68e8b976b009e0558035", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentfb330328f1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApioneBasePathMapping": { + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "DomainName": "example.com" - } - }, - "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" - } - ] - } - }, - "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "one", - "DomainName": { - "Ref": "ApiGatewayDomainName0caaf24ab1" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, - "MyApiDeploymentfb330328f1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: fb330328f152e4bb4b7d68e8b976b009e0558035" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentfb330328f1" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroupbd00d962a4": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "openapi": "3.0.1" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "HostedZoneId": "ZQ1UAL4EFZVME", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json index 98a21b9e22..c5fe451e4a 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name.json @@ -1,205 +1,205 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { + "ApiGatewayDomainName0caaf24ab1": { + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "DomainName": "example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment9239fa9a13": { + "Properties": { + "Description": "RestApi deployment id: 9239fa9a13216200ab5bf11c04507c61842a50a7", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment9239fa9a13" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApioneBasePathMapping": { + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "DomainName": "example.com" - } - }, - "MyApiDeployment9239fa9a13": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 9239fa9a13216200ab5bf11c04507c61842a50a7" - } - }, - "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "one", - "DomainName": { - "Ref": "ApiGatewayDomainName0caaf24ab1" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment9239fa9a13" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", "Properties": { - "HostedZoneName": "www.my-domain.com.", + "HostedZoneName": "www.my-domain.com.", "RecordSets": [ { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] - } - }, - "Type": "A", - "Name": "example.com" - }, + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "A" + }, { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] - } - }, - "Type": "AAAA", - "Name": "example.com" + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "AAAA" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "openapi": "3.0.1" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name_http.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name_http.json index 351eeedb83..98895e4b3e 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name_http.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_hosted_zone_name_http.json @@ -1,191 +1,191 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV20caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": "example.com", + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointType": "REGIONAL" } - ] - } - }, + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", + }, + "AutoDeploy": true, + "StageName": "Prod", "Tags": { "httpapi:createdBy": "SAM" } - } - }, + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "MyApioneApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", "Properties": { "ApiId": { "Ref": "MyApi" - }, + }, + "ApiMappingKey": "one", "DomainName": { "Ref": "ApiGatewayDomainNameV20caaf24ab1" - }, - "ApiMappingKey": "one", + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "ApiGatewayDomainNameV20caaf24ab1": { - "Type": "AWS::ApiGatewayV2::DomainName", + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { "Properties": { - "DomainName": "example.com", - "DomainNameConfigurations": [ + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointType": "REGIONAL" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneName": "www.my-domain.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFetchPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup456ebaf280": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + }, + "Name": "example.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_http.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_http.json index 34e7a8e9df..871cb5c974 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53_http.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_http.json @@ -1,209 +1,209 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV20caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": "example.com", + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointType": "REGIONAL" } - ] - } - }, + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "MyApioneApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", "Properties": { "ApiId": { "Ref": "MyApi" - }, + }, + "ApiMappingKey": "one", "DomainName": { "Ref": "ApiGatewayDomainNameV20caaf24ab1" - }, - "ApiMappingKey": "one", + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ApiGatewayDomainNameV20caaf24ab1": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "example.com", - "DomainNameConfigurations": [ - { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointType": "REGIONAL" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermission": { "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFetchPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroupbd00d962a4": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" + "HostedZoneId": "ZQ1UAL4EFZVME", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + }, + "Name": "example.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + }, + "Name": "example.com", + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple.json index 22f7744482..5e64d4738f 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple.json @@ -2,28 +2,31 @@ "AWSTemplateFormatVersion": "2010-09-09", "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", "Resources": { - "ApiGatewayAdminTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminOne": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminTwoDeployment61887a4eed" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminOneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName5fe29fe649" @@ -34,108 +37,132 @@ "Stage": { "Ref": "ApiGatewayAdminOneProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ApiGatewayAdminOneDeploymentdd3f545183": { + "Properties": { + "Description": "RestApi deployment id: dd3f545183668c401e771fd9a377cfeadcf88a35", + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayAdminOneProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayAdminOneDeploymentdd3f545183" }, - "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Prod", - "TracingEnabled": true, "MethodSettings": [ { "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } - }, - "ApiGatewayAdminThreeDeployment7541e97159": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7541e971598cffe7cafab030d3fccc687d508f59", - "RestApiId": { - "Ref": "ApiGatewayAdminThree" - }, - "StageName": "Stage" - } - }, - "ApiGatewayAdminOneDeploymentdd3f545183": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: dd3f545183668c401e771fd9a377cfeadcf88a35", + ], "RestApiId": { "Ref": "ApiGatewayAdminOne" }, - "StageName": "Stage" - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminThree": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminTwoDeployment61887a4eed": { - "Type": "AWS::ApiGateway::Deployment", + "ApiGatewayAdminThreeBasePathMapping": { "Properties": { - "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "DomainName": { + "Ref": "ApiGatewayDomainName41bfc7f9c4" + }, "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminThree" + }, + "Stage": { + "Ref": "ApiGatewayAdminThreeProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ApiGatewayAdminThreeDeployment7541e97159": { + "Properties": { + "Description": "RestApi deployment id: 7541e971598cffe7cafab030d3fccc687d508f59", + "RestApiId": { + "Ref": "ApiGatewayAdminThree" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiGatewayAdminThree": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayAdminThreeDeployment7541e97159" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminThree" + }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayAdminTwo": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, "swagger": "2.0" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ApiGatewayDomainName5fe29fe649": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.one.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminTwoBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName3fd2dbd8f8" @@ -146,163 +173,136 @@ "Stage": { "Ref": "ApiGatewayAdminTwoProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayAdminTwo": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminTwoDeployment61887a4eed": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" + "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiGatewayAdminTwoProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayAdminTwoDeployment61887a4eed" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, "ApiGatewayDomainName41bfc7f9c4": { - "Type": "AWS::ApiGateway::DomainName", "Properties": { - "RegionalCertificateArn": "arn::cert::abc", "DomainName": "admin.three.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } - }, - "ApiGatewayAdminThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminThreeDeployment7541e97159" }, - "RestApiId": { - "Ref": "ApiGatewayAdminThree" - }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminThreeBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayDomainName5fe29fe649": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName41bfc7f9c4" - }, - "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "DomainName": "admin.one.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "Stage": { - "Ref": "ApiGatewayAdminThreeProdStage" - } - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", "Properties": { "HostedZoneId": "abc123456", "RecordSets": [ { - "Name": "admin.two.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.two.amazon.com", + "Type": "A" }, { - "Name": "admin.three.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName41bfc7f9c4", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName41bfc7f9c4", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.three.amazon.com", + "Type": "A" }, { - "Name": "admin.one.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName5fe29fe649", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName5fe29fe649", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.one.amazon.com", + "Type": "A" } ] - } - }, - "ApiGatewayAdminOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json b/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json index 26b978e901..087c720574 100644 --- a/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json +++ b/tests/translator/output/aws-cn/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json @@ -7,100 +7,99 @@ } }, "Resources": { - "RecordSetGroupd9cb5a3e02": { - "Type": "AWS::Route53::RecordSetGroup", + "ApiGatewayAdminOne": { "Properties": { - "HostedZoneId": { - "Fn::Sub": "{{MyHostedZoneId}}" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "RecordSets": [ - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" - ] - } - } - } - ] - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminOneBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminTwoDeploymentca2a75b5dd" + "DomainName": { + "Ref": "ApiGatewayDomainName5fe29fe649" }, "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminOne" }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Stage": { + "Ref": "ApiGatewayAdminOneProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayDomainName5fe29fe649": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminOneDeployment066bb1ceae": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.one.amazon.com", - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "Description": "RestApi deployment id: 066bb1ceaebd0cafae99258bbe7130af8b676372", + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayAdminOneProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayAdminOneDeployment066bb1ceae" }, - "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Prod", - "TracingEnabled": true, "MethodSettings": [ { "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminThree": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminThreeBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName41bfc7f9c4" @@ -111,215 +110,216 @@ "Stage": { "Ref": "ApiGatewayAdminThreeProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayAdminOneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayAdminThreeDeployment169349c1e9": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName5fe29fe649" - }, + "Description": "RestApi deployment id: 169349c1e96a0f130ee35f7bb9d83b042c386d6f", "RestApiId": { - "Ref": "ApiGatewayAdminOne" + "Ref": "ApiGatewayAdminThree" }, - "Stage": { - "Ref": "ApiGatewayAdminOneProdStage" - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "RecordSetGroupd28e0e19d0": { - "Type": "AWS::Route53::RecordSetGroup", + "ApiGatewayAdminThreeProdStage": { "Properties": { - "HostedZoneId": { - "Ref": "MyHostedZoneId" + "DeploymentId": { + "Ref": "ApiGatewayAdminThreeDeployment169349c1e9" }, - "RecordSets": [ - { - "Name": "admin.three.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName41bfc7f9c4", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName41bfc7f9c4", - "RegionalDomainName" - ] - } - } - }, + "MethodSettings": [ { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName5fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName5fe29fe649", - "RegionalDomainName" - ] - } - } + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } - }, - "ApiGatewayAdminOneDeployment066bb1ceae": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 066bb1ceaebd0cafae99258bbe7130af8b676372", + ], "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Stage" - } - }, - "ApiGatewayAdminTwoBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName3fd2dbd8f8" - }, - "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminThree" }, - "Stage": { - "Ref": "ApiGatewayAdminTwoProdStage" - } - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, "ApiGatewayAdminTwo": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, "swagger": "2.0" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ApiGatewayDomainName41bfc7f9c4": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.three.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminTwoBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminThreeDeployment169349c1e9" + "DomainName": { + "Ref": "ApiGatewayDomainName3fd2dbd8f8" }, "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "Ref": "ApiGatewayAdminTwo" }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Stage": { + "Ref": "ApiGatewayAdminTwoProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, "ApiGatewayAdminTwoDeploymentca2a75b5dd": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: ca2a75b5dd3713c71543e80f2b6f5aac9538ea9c", "RestApiId": { "Ref": "ApiGatewayAdminTwo" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiGatewayAdminThree": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminTwoProdStage": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" + "DeploymentId": { + "Ref": "ApiGatewayAdminTwoDeploymentca2a75b5dd" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminThreeDeployment169349c1e9": { - "Type": "AWS::ApiGateway::Deployment", + "ApiGatewayDomainName41bfc7f9c4": { "Properties": { - "Description": "RestApi deployment id: 169349c1e96a0f130ee35f7bb9d83b042c386d6f", - "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "DomainName": "admin.three.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Stage" - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminOne": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayDomainName5fe29fe649": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, + "DomainName": "admin.one.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "RecordSetGroupd28e0e19d0": { + "Properties": { + "HostedZoneId": { + "Ref": "MyHostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName41bfc7f9c4", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName41bfc7f9c4", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.three.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName5fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName5fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + }, + "RecordSetGroupd9cb5a3e02": { + "Properties": { + "HostedZoneId": { + "Fn::Sub": "{{MyHostedZoneId}}" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_default_aws_iam_auth.json b/tests/translator/output/aws-cn/api_with_default_aws_iam_auth.json index 4173a6f216..73168ab5c5 100644 --- a/tests/translator/output/aws-cn/api_with_default_aws_iam_auth.json +++ b/tests/translator/output/aws-cn/api_with_default_aws_iam_auth.json @@ -1,153 +1,43 @@ { "Resources": { - "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithAwsIamAuthRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentd0103947f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - }, - "Description": "RestApi deployment id: d0103947f7e2e1d52ca7afac92f5afc8339a051b", - "StageName": "Stage" - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithAwsIamAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } - } - ] - } - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeploymentc8adfb74cf" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } - }, - "MyApiWithAwsIamAuthAndDefaultInvokeRoleProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentd0103947f7" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - }, - "StageName": "Prod" - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithAwsIamAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - } - } - ] - } - } - }, - "MyApiWithAwsIamAuthDeploymentc8adfb74cf": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "Description": "RestApi deployment id: c8adfb74cfae8b8052802a21a258ecbd5178d144", - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthAndCustomInvokeRole": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithAwsIamAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "post": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -157,59 +47,47 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithAwsIamAuthAndCustomInvokeRoleProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRoleDeployment2a6ecd9264" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - }, - "StageName": "Prod" - } - }, - "MyApiWithAwsIamAuthAndDefaultInvokeRole": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithAwsIamAuthAndCustomInvokeRole": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "put": { + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -219,57 +97,69 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithAwsIamAuthAndCustomInvokeRoleDeployment2a6ecd9264": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 2a6ecd9264d4f59054caa89a94960604594cd94f", "RestApiId": { "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" }, - "Description": "RestApi deployment id: 2a6ecd9264d4f59054caa89a94960604594cd94f", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithAwsIamAuthAndCustomInvokeRoleProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRoleDeployment2a6ecd9264" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRole": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "get": { + "put": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -279,43 +169,142 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentd0103947f7": { + "Properties": { + "Description": "RestApi deployment id: d0103947f7e2e1d52ca7afac92f5afc8339a051b", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRoleProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentd0103947f7" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthDeploymentc8adfb74cf": { + "Properties": { + "Description": "RestApi deployment id: c8adfb74cfae8b8052802a21a258ecbd5178d144", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeploymentc8adfb74cf" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionWithAwsIamAuth": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithAwsIamAuthRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionWithAwsIamAuth" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithAwsIamAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithAwsIamAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -328,9 +317,20 @@ ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_default_aws_iam_auth_and_no_auth_route.json b/tests/translator/output/aws-cn/api_with_default_aws_iam_auth_and_no_auth_route.json index 08b3d0b79f..35732f6c6b 100644 --- a/tests/translator/output/aws-cn/api_with_default_aws_iam_auth_and_no_auth_route.json +++ b/tests/translator/output/aws-cn/api_with_default_aws_iam_auth_and_no_auth_route.json @@ -1,7 +1,128 @@ { "Resources": { + "MyApiWithAwsIamAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/iam": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/none": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthDeploymentfbe9aee08e": { + "Properties": { + "Description": "RestApi deployment id: fbe9aee08eb164bd4de9a7a7c91782c10b86d7df", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeploymentfbe9aee08e" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +142,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +154,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -72,10 +163,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithNoAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +175,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -93,10 +184,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithNoAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +196,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/none", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -114,10 +205,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithNoAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithNoAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +217,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/none", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -135,129 +226,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithAwsIamAuthRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "NONE": [] - } - ] - } - }, - "/any/iam": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - } - }, - "/any/none": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "NONE": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "AWS_IAM": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithAwsIamAuthDeploymentfbe9aee08e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: fbe9aee08eb164bd4de9a7a7c91782c10b86d7df", - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeploymentfbe9aee08e" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_disable_api_execute_endpoint.json b/tests/translator/output/aws-cn/api_with_disable_api_execute_endpoint.json index 7b13a036c5..2869ae0f36 100644 --- a/tests/translator/output/aws-cn/api_with_disable_api_execute_endpoint.json +++ b/tests/translator/output/aws-cn/api_with_disable_api_execute_endpoint.json @@ -1,59 +1,51 @@ { "Resources": { - "ApiGatewayApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-endpoint-configuration": { - "disableExecuteApiEndpoint": true - } + "Code": { + "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" ] }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiGatewayApiDeployment31ce724e39": { - "Type": "AWS::ApiGateway::Deployment", + "ApiFunctionApiEventPermissionprod": { "Properties": { - "RestApiId": { - "Ref": "ApiGatewayApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" }, - "Description": "RestApi deployment id: 31ce724e3998cb16b80266cfb4868670a87430bf", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ApiGatewayApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -66,64 +58,71 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayApi": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-endpoint-configuration": { + "disableExecuteApiEndpoint": true + } }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiFunctionApiEventPermissionprod": { - "Type": "AWS::Lambda::Permission", + "ApiGatewayApiDeployment31ce724e39": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" + "Description": "RestApi deployment id: 31ce724e3998cb16b80266cfb4868670a87430bf", + "RestApiId": { + "Ref": "ApiGatewayApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ApiGatewayApi" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayApiprodStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayApiDeployment31ce724e39" @@ -132,7 +131,8 @@ "Ref": "ApiGatewayApi" }, "StageName": "prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_fail_on_warnings.json b/tests/translator/output/aws-cn/api_with_fail_on_warnings.json index 97c968816a..d1c4a9a14e 100644 --- a/tests/translator/output/aws-cn/api_with_fail_on_warnings.json +++ b/tests/translator/output/aws-cn/api_with_fail_on_warnings.json @@ -1,57 +1,51 @@ { "Resources": { - "ApiGatewayApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0" + "Code": { + "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" }, - "FailOnWarnings": true, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" ] }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiGatewayApiDeploymentb0ed1521b2": { - "Type": "AWS::ApiGateway::Deployment", + "ApiFunctionApiEventPermissionprod": { "Properties": { - "RestApiId": { - "Ref": "ApiGatewayApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" }, - "Description": "RestApi deployment id: b0ed1521b2c5e65da74d55d16b139143ae483503", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ApiGatewayApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -64,64 +58,69 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayApi": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "FailOnWarnings": true, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiFunctionApiEventPermissionprod": { - "Type": "AWS::Lambda::Permission", + "ApiGatewayApiDeploymentb0ed1521b2": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" + "Description": "RestApi deployment id: b0ed1521b2c5e65da74d55d16b139143ae483503", + "RestApiId": { + "Ref": "ApiGatewayApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ApiGatewayApi" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayApiprodStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayApiDeploymentb0ed1521b2" @@ -130,7 +129,8 @@ "Ref": "ApiGatewayApi" }, "StageName": "prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_gateway_responses.json b/tests/translator/output/aws-cn/api_with_gateway_responses.json index a0eb308b66..48a762aac0 100644 --- a/tests/translator/output/aws-cn/api_with_gateway_responses.json +++ b/tests/translator/output/aws-cn/api_with_gateway_responses.json @@ -1,89 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiDeployment9196b651da": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9196b651da2a4564831de870a4b6cf9c6bed29b0", - "StageName": "Stage" - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -91,9 +27,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -108,10 +44,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment9196b651da": { + "Properties": { + "Description": "RestApi deployment id: 9196b651da2a4564831de870a4b6cf9c6bed29b0", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment9196b651da" @@ -120,28 +66,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_gateway_responses_all.json b/tests/translator/output/aws-cn/api_with_gateway_responses_all.json index 3605cc0c2f..4651fbea2e 100644 --- a/tests/translator/output/aws-cn/api_with_gateway_responses_all.json +++ b/tests/translator/output/aws-cn/api_with_gateway_responses_all.json @@ -1,89 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymenta27cf1b1d7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a27cf1b1d762583a4e0873d7a1eb25bea7966067", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -98,9 +34,9 @@ }, "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", - "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", + "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", "gatewayresponse.path.PathKey": "'path-value'", "gatewayresponse.querystring.QueryStringKey": "'query-string-value'" }, @@ -117,10 +53,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta27cf1b1d7": { + "Properties": { + "Description": "RestApi deployment id: a27cf1b1d762583a4e0873d7a1eb25bea7966067", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymenta27cf1b1d7" @@ -129,28 +75,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_gateway_responses_all_openapi_3.json b/tests/translator/output/aws-cn/api_with_gateway_responses_all_openapi_3.json index 140250a6b5..c1532c173c 100644 --- a/tests/translator/output/aws-cn/api_with_gateway_responses_all_openapi_3.json +++ b/tests/translator/output/aws-cn/api_with_gateway_responses_all_openapi_3.json @@ -1,155 +1,155 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiDeploymenta2f31986fe": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a2f31986fe718bd69858a109ac2b401fb7d8560f" - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0", + }, "x-amazon-apigateway-gateway-responses": { "QUOTA_EXCEEDED": { "responseParameters": { "gatewayresponse.header.Retry-After": "'31536000'" - }, - "responseTemplates": {}, + }, + "responseTemplates": {}, "statusCode": "429" - }, + }, "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", - "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", - "gatewayresponse.path.PathKey": "'path-value'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", + "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.path.PathKey": "'path-value'", "gatewayresponse.querystring.QueryStringKey": "'query-string-value'" - }, - "responseTemplates": {}, + }, + "responseTemplates": {}, "statusCode": "401" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta2f31986fe": { + "Properties": { + "Description": "RestApi deployment id: a2f31986fe718bd69858a109ac2b401fb7d8560f", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeploymenta2f31986fe" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_gateway_responses_implicit.json b/tests/translator/output/aws-cn/api_with_gateway_responses_implicit.json index cb116f10ed..f49f0e9473 100644 --- a/tests/translator/output/aws-cn/api_with_gateway_responses_implicit.json +++ b/tests/translator/output/aws-cn/api_with_gateway_responses_implicit.json @@ -1,13 +1,12 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionRole", @@ -17,26 +16,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -49,74 +59,41 @@ ] } } - ] - } - } - }, - "ServerlessRestApiDeployment9196b651da": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 9196b651da2a4564831de870a4b6cf9c6bed29b0", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment9196b651da" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -124,9 +101,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -142,7 +119,30 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment9196b651da": { + "Properties": { + "Description": "RestApi deployment id: 9196b651da2a4564831de870a4b6cf9c6bed29b0", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment9196b651da" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_gateway_responses_minimal.json b/tests/translator/output/aws-cn/api_with_gateway_responses_minimal.json index fdc244668f..de4204bb76 100644 --- a/tests/translator/output/aws-cn/api_with_gateway_responses_minimal.json +++ b/tests/translator/output/aws-cn/api_with_gateway_responses_minimal.json @@ -1,79 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -93,20 +39,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeployment8f2919f3e3": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 8f2919f3e3e2816355b75920c4482c085c6124a2", "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: 8f2919f3e3e2816355b75920c4482c085c6124a2", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment8f2919f3e3" @@ -115,28 +61,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_gateway_responses_string_status_code.json b/tests/translator/output/aws-cn/api_with_gateway_responses_string_status_code.json index a0eb308b66..48a762aac0 100644 --- a/tests/translator/output/aws-cn/api_with_gateway_responses_string_status_code.json +++ b/tests/translator/output/aws-cn/api_with_gateway_responses_string_status_code.json @@ -1,89 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiDeployment9196b651da": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9196b651da2a4564831de870a4b6cf9c6bed29b0", - "StageName": "Stage" - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -91,9 +27,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -108,10 +44,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment9196b651da": { + "Properties": { + "Description": "RestApi deployment id: 9196b651da2a4564831de870a4b6cf9c6bed29b0", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment9196b651da" @@ -120,28 +66,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_identity_intrinsic.json b/tests/translator/output/aws-cn/api_with_identity_intrinsic.json index 84b61b86c7..bc65289466 100644 --- a/tests/translator/output/aws-cn/api_with_identity_intrinsic.json +++ b/tests/translator/output/aws-cn/api_with_identity_intrinsic.json @@ -5,24 +5,21 @@ }, "Resources": { "APIGateway": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, - "swagger": "2.0", "securityDefinitions": { "SomeAuthorizer": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerResultTtlInSeconds": { "Fn::If": [ "isProd", @@ -30,7 +27,6 @@ 0 ] }, - "identitySource": "method.request.header.Accept", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -38,11 +34,14 @@ "__FunctionArn__": "SomeArn" } ] - } + }, + "identitySource": "method.request.header.Accept", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -52,14 +51,36 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "APIGatewayDeployment2621a8c79f": { + "Properties": { + "Description": "RestApi deployment id: 2621a8c79f8f26195374aad642039f511d020a75", + "RestApiId": { + "Ref": "APIGateway" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "APIGatewayProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "APIGatewayDeployment2621a8c79f" + }, + "RestApiId": { + "Ref": "APIGateway" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "APIGatewaySomeAuthorizerAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": "SomeArn", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", @@ -70,29 +91,8 @@ } ] } - } - }, - "APIGatewayProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "APIGatewayDeployment2621a8c79f" - }, - "RestApiId": { - "Ref": "APIGateway" - }, - "StageName": "Prod" - } - }, - "APIGatewayDeployment2621a8c79f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "APIGateway" - }, - "Description": "RestApi deployment id: 2621a8c79f8f26195374aad642039f511d020a75", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_if_conditional_with_resource_policy.json b/tests/translator/output/aws-cn/api_with_if_conditional_with_resource_policy.json index f3b5ca796a..a454e9299c 100644 --- a/tests/translator/output/aws-cn/api_with_if_conditional_with_resource_policy.json +++ b/tests/translator/output/aws-cn/api_with_if_conditional_with_resource_policy.json @@ -8,8 +8,106 @@ } }, "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/one": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/three": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/two": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Fn::If": [ + "C1", + { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment80cc69e78e": { + "Properties": { + "Description": "RestApi deployment id: 80cc69e78e41e167db71ceb084808e61c9235318", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -29,40 +127,10 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "ExplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -80,10 +148,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "ExplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -101,10 +169,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPutHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -113,7 +181,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", { "__ApiId__": { "Ref": "ExplicitApi" @@ -122,10 +190,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPutHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -134,7 +202,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", { "__ApiId__": { "Ref": "ExplicitApi" @@ -143,109 +211,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ExplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Fn::If": [ - "C1", - { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - }, - { - "Ref": "AWS::NoValue" - } - ] - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment80cc69e78e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 80cc69e78e41e167db71ceb084808e61c9235318", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment80cc69e78e" @@ -254,7 +253,8 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_incompatible_stage_name.json b/tests/translator/output/aws-cn/api_with_incompatible_stage_name.json index 0cf9ef1656..fd4fc3ee28 100644 --- a/tests/translator/output/aws-cn/api_with_incompatible_stage_name.json +++ b/tests/translator/output/aws-cn/api_with_incompatible_stage_name.json @@ -1,304 +1,304 @@ { "Resources": { - "UnderscoreApiStageb34d3ad84e": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "UnderscoreApiDeploymentd4074182ff" - }, - "RestApiId": { - "Ref": "UnderscoreApi" - }, - "StageName": "hoge_fuga" - } - }, - "UnderscoreApi": { - "Type": "AWS::ApiGateway::RestApi", + "HyphenApi": { "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UnderscoreFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HyphenFunction.Arn}/invocations" + } } } } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "UnderscoreFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "UnderscoreApiDeploymentd4074182ff": { - "Type": "AWS::ApiGateway::Deployment", + "HyphenApiDeployment52a312db45": { "Properties": { + "Description": "RestApi deployment id: 52a312db455cee5b3a5fca6c9c078593381e179b", "RestApiId": { - "Ref": "UnderscoreApi" - }, - "Description": "RestApi deployment id: d4074182ff399887934824aa702b5573c9ad3f7c", + "Ref": "HyphenApi" + }, "StageName": "Stage" - } - }, - "HyphenFunctionGetHtmlPermission0c8ecc62cb": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HyphenFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HyphenApi" - } - ] - } - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "HyphenApiStage0c8ecc62cb": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "HyphenApiDeployment52a312db45" - }, + }, "RestApiId": { "Ref": "HyphenApi" - }, + }, "StageName": "hoge-fuga" - } - }, - "UnderscoreFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HyphenFunction": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "UnderscoreFunctionRole", + "HyphenFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "UnderscoreFunctionGetHtmlPermissionb34d3ad84e": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HyphenFunctionGetHtmlPermission0c8ecc62cb": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "UnderscoreFunction" - }, + "Ref": "HyphenFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "UnderscoreApi" + "__ApiId__": "HyphenApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HyphenFunction": { - "Type": "AWS::Lambda::Function", + "HyphenFunctionRole": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HyphenFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HyphenApiDeployment52a312db45": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HyphenApi" - }, - "Description": "RestApi deployment id: 52a312db455cee5b3a5fca6c9c078593381e179b", - "StageName": "Stage" - } - }, - "HyphenApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "UnderscoreApi": { "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HyphenFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UnderscoreFunction.Arn}/invocations" + } } } } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "HyphenFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "UnderscoreApiDeploymentd4074182ff": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Description": "RestApi deployment id: d4074182ff399887934824aa702b5573c9ad3f7c", + "RestApiId": { + "Ref": "UnderscoreApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "UnderscoreApiStageb34d3ad84e": { + "Properties": { + "DeploymentId": { + "Ref": "UnderscoreApiDeploymentd4074182ff" + }, + "RestApiId": { + "Ref": "UnderscoreApi" + }, + "StageName": "hoge_fuga" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "UnderscoreFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "UnderscoreFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "UnderscoreFunctionGetHtmlPermissionb34d3ad84e": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "UnderscoreFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "UnderscoreApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "UnderscoreFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_ip_range_blacklist.json b/tests/translator/output/aws-cn/api_with_ip_range_blacklist.json index f876a1bd85..66664b857a 100644 --- a/tests/translator/output/aws-cn/api_with_ip_range_blacklist.json +++ b/tests/translator/output/aws-cn/api_with_ip_range_blacklist.json @@ -1,196 +1,196 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5e467ed97e" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessRestApiDeployment5e467ed97e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5e467ed97e429eadbf1e8e5a36ac9738d37bb79f", - "StageName": "Stage" - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/get": { "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", - { - "__Stage__": "Prod" - } - ] - } - ], - "Effect": "Allow", + "Action": "execute-api:Invoke", + "Effect": "Allow", "Principal": { "AWS": [ "12345" ] - } - }, - { - "Action": "execute-api:Invoke", + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": "*" - }, + ] + }, { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "IpAddress": { "aws:SourceIp": [ "1.2.3.4" ] } - }, - "Principal": "*" + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/PUT/get", + { + "__Stage__": "Prod" + } + ] + } + ] } - ] + ], + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5e467ed97e": { + "Properties": { + "Description": "RestApi deployment id: 5e467ed97e429eadbf1e8e5a36ac9738d37bb79f", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5e467ed97e" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_ip_range_whitelist.json b/tests/translator/output/aws-cn/api_with_ip_range_whitelist.json index a9d254e503..e8be3ab400 100644 --- a/tests/translator/output/aws-cn/api_with_ip_range_whitelist.json +++ b/tests/translator/output/aws-cn/api_with_ip_range_whitelist.json @@ -1,199 +1,199 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment4dbd43b8e2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 4dbd43b8e229c09245208ff5a44c9a083227a560", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment4dbd43b8e2" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/get": { "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": "*" - }, + ] + }, { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { - "NotIpAddress": { + "IpAddress": { "aws:SourceIp": [ "1.2.3.4" ] } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" + ] } - ] + ], + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment4dbd43b8e2": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: 4dbd43b8e229c09245208ff5a44c9a083227a560", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment4dbd43b8e2" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_method_aws_iam_auth.json b/tests/translator/output/aws-cn/api_with_method_aws_iam_auth.json index ab6cc030f4..0b0babc403 100644 --- a/tests/translator/output/aws-cn/api_with_method_aws_iam_auth.json +++ b/tests/translator/output/aws-cn/api_with_method_aws_iam_auth.json @@ -1,7 +1,128 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "put": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/one": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment467c912da1": { + "Properties": { + "Description": "RestApi deployment id: 467c912da1971538d628768c65d8008b454fdf27", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment467c912da1" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +142,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +154,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +163,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +175,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,10 +184,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +196,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/one", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -114,10 +205,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +217,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/one", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -135,129 +226,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithAwsIamAuthRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - } - }, - "/any/one": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithoutAuthDeployment467c912da1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 467c912da1971538d628768c65d8008b454fdf27", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment467c912da1" - }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_method_settings.json b/tests/translator/output/aws-cn/api_with_method_settings.json index 5e09017cd7..9dc0202868 100644 --- a/tests/translator/output/aws-cn/api_with_method_settings.json +++ b/tests/translator/output/aws-cn/api_with_method_settings.json @@ -1,193 +1,193 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "MethodSettings": [ + { + "DataTraceEnabled": true, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": true, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "MethodSettings": [ - { - "HttpMethod": "*", - "MetricsEnabled": true, - "ResourcePath": "/*", - "DataTraceEnabled": true, - "LoggingLevel": "INFO" - } - ], - "RestApiId": { - "Ref": "ExplicitApi" - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "MethodSettings": [ + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "HttpMethod": "*", - "MetricsEnabled": true, - "ResourcePath": "/*", - "DataTraceEnabled": true, - "LoggingLevel": "INFO" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcb4fb12558" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcb4fb12558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcb4fb12558": { + "Properties": { + "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcb4fb12558" + }, + "MethodSettings": [ + { + "DataTraceEnabled": true, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": true, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_minimum_compression_size.json b/tests/translator/output/aws-cn/api_with_minimum_compression_size.json index ce1ad07b60..3f015bd954 100644 --- a/tests/translator/output/aws-cn/api_with_minimum_compression_size.json +++ b/tests/translator/output/aws-cn/api_with_minimum_compression_size.json @@ -1,177 +1,177 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "MinimumCompressionSize": 256, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "MinimumCompressionSize": 256, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcb4fb12558" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentcb4fb12558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, - "MinimumCompressionSize": 1024, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, + "MinimumCompressionSize": 1024, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcb4fb12558": { + "Properties": { + "Description": "RestApi deployment id: cb4fb1255811b7b6a25dd35f23ee7ad133003b89", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcb4fb12558" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_mode.json b/tests/translator/output/aws-cn/api_with_mode.json index 46332e2e4b..80cbc9c2cf 100644 --- a/tests/translator/output/aws-cn/api_with_mode.json +++ b/tests/translator/output/aws-cn/api_with_mode.json @@ -1,78 +1,6 @@ { "Resources": { - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "Api" - }, - "StageName": "Prod" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "Api" - } - ] - } - } - }, - "ApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, "Api": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "BodyS3Location": { "Bucket": "sam-demo-bucket", @@ -88,10 +16,32 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -107,11 +57,61 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "Api", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_no_properties.json b/tests/translator/output/aws-cn/api_with_no_properties.json index 5eaf3b3d22..6a26033aa4 100644 --- a/tests/translator/output/aws-cn/api_with_no_properties.json +++ b/tests/translator/output/aws-cn/api_with_no_properties.json @@ -1,7 +1,54 @@ { "Resources": { + "HTTPApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "HTTPApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "HTTPApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +68,31 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HTTPApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +105,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,74 +117,8 @@ "Value": "SAM" } ] - } - }, - "HtmlFunctionGetHtmlPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": "HTTPApi", - "__Stage__": "*" - } - ] - } - } - }, - "HTTPApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "openapi": "3.0.1", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "payloadFormatVersion": "2.0", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, - "HTTPApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HTTPApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/api_with_open_api_version.json b/tests/translator/output/aws-cn/api_with_open_api_version.json index b29f1cc496..725e49cfd5 100644 --- a/tests/translator/output/aws-cn/api_with_open_api_version.json +++ b/tests/translator/output/aws-cn/api_with_open_api_version.json @@ -1,7 +1,50 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {} + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentd9a0f2ae4f": { + "Properties": { + "Description": "RestApi deployment id: d9a0f2ae4fe2d97b9b91644934a878b6a08cf1c3", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentd9a0f2ae4f" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +64,10 @@ "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +76,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +85,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +97,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,187 +106,173 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {}, - "openapi": "3.0.1" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeploymentd9a0f2ae4f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: d9a0f2ae4fe2d97b9b91644934a878b6a08cf1c3", - "RestApiId": { - "Ref": "ExplicitApi" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentd9a0f2ae4f" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } } } - } - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } }, - "responses": {} - }, - "options": { "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } + }, + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + } + }, + "/any": { + "options": { "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } } } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "*" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } } } } - }, - "openapi": "3.0.1" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + } }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentd5853601f5": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: d5853601f56a2ac553fd346fd4b02b5fbd727be7", "RestApiId": { "Ref": "ServerlessRestApi" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentd5853601f5" @@ -282,7 +281,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_open_api_version_2.json b/tests/translator/output/aws-cn/api_with_open_api_version_2.json index c8c25f565e..2c1808ea65 100644 --- a/tests/translator/output/aws-cn/api_with_open_api_version_2.json +++ b/tests/translator/output/aws-cn/api_with_open_api_version_2.json @@ -1,7 +1,50 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment4154e1c30c": { + "Properties": { + "Description": "RestApi deployment id: 4154e1c30c97469d4946280461125dbfd4324f15", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment4154e1c30c" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +64,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +76,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +85,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +97,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,191 +106,177 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {} - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment4154e1c30c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 4154e1c30c97469d4946280461125dbfd4324f15", - "RestApiId": { - "Ref": "ExplicitApi" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment4154e1c30c" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } } }, "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment332dfbf8ff": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 332dfbf8ff85ff84812777af394f9f427b87611c", "RestApiId": { "Ref": "ServerlessRestApi" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment332dfbf8ff" @@ -286,7 +285,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_openapi_definition_body_no_flag.json b/tests/translator/output/aws-cn/api_with_openapi_definition_body_no_flag.json index 23804071b5..ca6140b3fb 100644 --- a/tests/translator/output/aws-cn/api_with_openapi_definition_body_no_flag.json +++ b/tests/translator/output/aws-cn/api_with_openapi_definition_body_no_flag.json @@ -1,277 +1,277 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeployment9252467a1e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9252467a1edc49ba35cb258640f5e3734cc9fab1", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "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" - } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.1.1", "components": { "securitySchemes": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.1.1", + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "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" + } + } + } + } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymente1212668e0" - } - } - }, - "ServerlessRestApiDeploymente1212668e0": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment9252467a1e": { "Properties": { + "Description": "RestApi deployment id: 9252467a1edc49ba35cb258640f5e3734cc9fab1", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: e1212668e096994ab32167666f5a877bd6ac5fad", + "Ref": "ExplicitApi" + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment9252467a1e" + }, "RestApiId": { "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", + }, + "StageName": "SomeStage", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment9252467a1e" } - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 } - }, + }, "Schema": [ { - "AttributeDataType": "String", - "Required": false, - "Name": "email" + "AttributeDataType": "String", + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, + }, + "Type": "AWS::Cognito::UserPool" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "MyCognitoAuth": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymente1212668e0": { + "Properties": { + "Description": "RestApi deployment id: e1212668e096994ab32167666f5a877bd6ac5fad", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente1212668e0" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/api_with_path_parameters.json b/tests/translator/output/aws-cn/api_with_path_parameters.json index a509e28fa4..3d2c59ee2b 100644 --- a/tests/translator/output/aws-cn/api_with_path_parameters.json +++ b/tests/translator/output/aws-cn/api_with_path_parameters.json @@ -1,7 +1,45 @@ { "Resources": { + "HtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +59,10 @@ "Value": "SAM" } ] - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "HtmlFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -70,10 +78,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -89,46 +97,38 @@ } ] } - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "HtmlFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "HtmlApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_resource_policy.json b/tests/translator/output/aws-cn/api_with_resource_policy.json index bcc3feffdc..7623816062 100644 --- a/tests/translator/output/aws-cn/api_with_resource_policy.json +++ b/tests/translator/output/aws-cn/api_with_resource_policy.json @@ -1,7 +1,97 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/one": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/three": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/two": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment521a434bab": { + "Properties": { + "Description": "RestApi deployment id: 521a434babdb65e910faa56d55382e6d84f9d789", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +111,10 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "ExplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,10 +132,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "ExplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -93,10 +153,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPutHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +165,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", { "__ApiId__": { "Ref": "ExplicitApi" @@ -114,10 +174,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPutHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +186,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", { "__ApiId__": { "Ref": "ExplicitApi" @@ -135,101 +195,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ExplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - } - } + ], + "Version": "2012-10-17" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment521a434bab": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 521a434babdb65e910faa56d55382e6d84f9d789", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment521a434bab" @@ -238,7 +237,8 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_resource_policy_global.json b/tests/translator/output/aws-cn/api_with_resource_policy_global.json index 0d7c8c732e..fa2446b380 100644 --- a/tests/translator/output/aws-cn/api_with_resource_policy_global.json +++ b/tests/translator/output/aws-cn/api_with_resource_policy_global.json @@ -2,247 +2,247 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { "StageName": { - "Default": "MyOwnStage", + "Default": "MyOwnStage", "Type": "String" } - }, + }, "Resources": { "AnotherApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0", + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { "Fn::If": [ - "C1", + "C1", { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*/*/*" ] - }, + }, { - "Action": "execute-api:Another", + "Action": "execute-api:Another", "Resource": [ "execute-api:/*/*/*" ] } ] - } + }, + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ExplicitApiDeploymenta5a5c4e3ff": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a5a5c4e3ff6901cf27436628359ed20300d34aa4", - "StageName": "Stage" - } - }, - "ExplicitApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymenta5a5c4e3ff" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": { - "Ref": "StageName" - } - } - }, - "ExplicitApiFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ExplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ExplicitApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "AnotherApiDeploymentfdf1387e0a": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: fdf1387e0a89fa15996401a79284cdaaf2c43844", "RestApiId": { "Ref": "AnotherApi" - }, - "Description": "RestApi deployment id: fdf1387e0a89fa15996401a79284cdaaf2c43844", + }, "StageName": "Stage" - } - }, - "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ExplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "AnotherApiStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "AnotherApiDeploymentfdf1387e0a" - }, + }, "RestApiId": { "Ref": "AnotherApi" - }, + }, "StageName": { "Ref": "StageName" } - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": 2.0, + }, + "swagger": 2.0, "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sts:AssumeRole", - "Effect": "Allow", + "Action": "sts:AssumeRole", + "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" } - }, + }, { "Fn::If": [ - "C1", + "C1", { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*/*/*" ] - }, + }, { - "Action": "execute-api:Blah", + "Action": "execute-api:Blah", "Resource": [ "execute-api:/*/*/*" ] } ] } - ] + ], + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta5a5c4e3ff": { + "Properties": { + "Description": "RestApi deployment id: a5a5c4e3ff6901cf27436628359ed20300d34aa4", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ExplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ExplicitApiFunctionGetHtmlPermissionStage": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ExplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ExplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ExplicitApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymenta5a5c4e3ff" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": { + "Ref": "StageName" + } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_resource_policy_global_implicit.json b/tests/translator/output/aws-cn/api_with_resource_policy_global_implicit.json index 636e827562..6722b86f46 100644 --- a/tests/translator/output/aws-cn/api_with_resource_policy_global_implicit.json +++ b/tests/translator/output/aws-cn/api_with_resource_policy_global_implicit.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MinimalFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MinimalFunctionAddItemAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/add", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MinimalFunctionAddItemAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MinimalFunctionAddItemPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/add", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,47 +62,76 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MinimalFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/any/add": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MinimalFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { "Action": "execute-api:Invoke", @@ -147,31 +145,32 @@ "execute-api:/*/*/*" ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment98196e5fed": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 98196e5feda626038eec9106c55ff6fa75bcd98a", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment98196e5fed" @@ -180,7 +179,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_resource_refs.json b/tests/translator/output/aws-cn/api_with_resource_refs.json index 42444227a5..54e031139d 100644 --- a/tests/translator/output/aws-cn/api_with_resource_refs.json +++ b/tests/translator/output/aws-cn/api_with_resource_refs.json @@ -1,7 +1,67 @@ { + "Outputs": { + "ExplicitApiDeployment": { + "Value": { + "Ref": "MyApiDeployment359f256a3b" + } + }, + "ExplicitApiStage": { + "Value": { + "Ref": "MyApifooStage" + } + }, + "ImplicitApiDeployment": { + "Value": { + "Ref": "ServerlessRestApiDeploymentc6687f83a5" + } + }, + "ImplicitApiStage": { + "Value": { + "Ref": "ServerlessRestApiProdStage" + } + } + }, "Resources": { + "MyApi": { + "Properties": { + "Body": { + "a": "swagger", + "this": "is" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment359f256a3b": { + "Properties": { + "Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApifooStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment359f256a3b" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "foo" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +81,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionGetHtmlAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,10 +102,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -93,107 +123,98 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "swagger" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiDeployment359f256a3b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyApifooStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment359f256a3b" - }, - "RestApiId": { - "Ref": "MyApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "foo" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/html": { - "get": { + "/any/html": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/html": { - "x-amazon-apigateway-any-method": { + "/html": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentc6687f83a5": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: c6687f83a5e49bc8768e484d2933dae0ed857fa5", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentc6687f83a5" @@ -202,29 +223,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } - } - }, - "Outputs": { - "ImplicitApiDeployment": { - "Value": { - "Ref": "ServerlessRestApiDeploymentc6687f83a5" - } - }, - "ImplicitApiStage": { - "Value": { - "Ref": "ServerlessRestApiProdStage" - } - }, - "ExplicitApiDeployment": { - "Value": { - "Ref": "MyApiDeployment359f256a3b" - } - }, - "ExplicitApiStage": { - "Value": { - "Ref": "MyApifooStage" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_security_definition_and_components.json b/tests/translator/output/aws-cn/api_with_security_definition_and_components.json index b1f5e6e920..914afadd1f 100644 --- a/tests/translator/output/aws-cn/api_with_security_definition_and_components.json +++ b/tests/translator/output/aws-cn/api_with_security_definition_and_components.json @@ -1,7 +1,90 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "schemas": { + "Error": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "Object" + } + }, + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment195f5bf5d0": { + "Properties": { + "Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment195f5bf5d0" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +104,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +122,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,91 +134,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiDeployment195f5bf5d0": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment195f5bf5d0" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - }, - "schemas": { - "Error": { - "type": "Object", - "properties": { - "message": { - "type": "string" - } - } - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_security_definition_and_no_components.json b/tests/translator/output/aws-cn/api_with_security_definition_and_no_components.json index 27bd3ad28d..c63fe3563e 100644 --- a/tests/translator/output/aws-cn/api_with_security_definition_and_no_components.json +++ b/tests/translator/output/aws-cn/api_with_security_definition_and_no_components.json @@ -1,7 +1,80 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment407993a935": { + "Properties": { + "Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment407993a935" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +94,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +112,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,81 +124,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment407993a935" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment407993a935": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_security_definition_and_none_components.json b/tests/translator/output/aws-cn/api_with_security_definition_and_none_components.json index 5f7d1aa071..5404fe80dd 100644 --- a/tests/translator/output/aws-cn/api_with_security_definition_and_none_components.json +++ b/tests/translator/output/aws-cn/api_with_security_definition_and_none_components.json @@ -1,7 +1,80 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment61b3921bb7": { + "Properties": { + "Description": "RestApi deployment id: 61b3921bb7522c20a8e0de1d24c974267f3ec17b", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment61b3921bb7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +94,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +112,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,81 +124,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment61b3921bb7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment61b3921bb7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 61b3921bb7522c20a8e0de1d24c974267f3ec17b", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_source_vpc_blacklist.json b/tests/translator/output/aws-cn/api_with_source_vpc_blacklist.json index f7f963051d..8ed7a6d45a 100644 --- a/tests/translator/output/aws-cn/api_with_source_vpc_blacklist.json +++ b/tests/translator/output/aws-cn/api_with_source_vpc_blacklist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionApiAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,81 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any/get": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/get": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -146,12 +145,19 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Condition": { + "StringEquals": { + "aws:SourceVpce": [ + "vpce-3456" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -161,19 +167,12 @@ } ] } - ], - "Principal": "*", - "Condition": { - "StringEquals": { - "aws:SourceVpce": [ - "vpce-3456" - ] - } - } + ] }, { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -183,12 +182,19 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Condition": { + "StringEquals": { + "aws:SourceVpce": [ + "vpce-3456" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -198,41 +204,34 @@ } ] } - ], - "Principal": "*", - "Condition": { - "StringEquals": { - "aws:SourceVpce": [ - "vpce-3456" - ] - } - } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment81f9873837": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 81f9873837e5d87c31bf575bf103161ecb7abc44", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment81f9873837" @@ -241,7 +240,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_source_vpc_whitelist.json b/tests/translator/output/aws-cn/api_with_source_vpc_whitelist.json index 2ed8374468..c92fad763e 100644 --- a/tests/translator/output/aws-cn/api_with_source_vpc_whitelist.json +++ b/tests/translator/output/aws-cn/api_with_source_vpc_whitelist.json @@ -1,13 +1,57 @@ { "Parameters": { "Vpc1": { - "Type": "String", - "Default": "vpc-1234" + "Default": "vpc-1234", + "Type": "String" } }, "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment5332c373d4": { + "Properties": { + "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment5332c373d4" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -26,40 +70,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionFetchAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionApiAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -68,7 +82,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/fetch", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/get", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -77,10 +91,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionApiAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionApiPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -89,7 +103,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/get", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -98,10 +112,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionFetchAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -110,7 +124,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/fetch", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -119,10 +133,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionFetchPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -131,7 +145,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -140,120 +154,105 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {} - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiDeployment5332c373d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment5332c373d4" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any/fetch": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/any/get": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/fetch": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/fetch": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -263,23 +262,10 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", - { - "__Stage__": "Prod" - } - ] - } - ], - "Principal": "*", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -287,26 +273,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/*/any/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -316,8 +300,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -325,26 +311,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/fetch", + "execute-api:/${__Stage__}/*/any/get", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -354,8 +338,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -363,26 +349,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/*/any/fetch", + "execute-api:/${__Stage__}/POST/fetch", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -392,8 +376,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -401,33 +387,46 @@ "vpc-5678" ] } - } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/*/any/fetch", + { + "__Stage__": "Prod" + } + ] + } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentc62c165bfb": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: c62c165bfb751bc0db21849d287f7065a7a0e8f8", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentc62c165bfb" @@ -436,7 +435,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_stage_tags.json b/tests/translator/output/aws-cn/api_with_stage_tags.json index 1e99128862..2cd544ace2 100644 --- a/tests/translator/output/aws-cn/api_with_stage_tags.json +++ b/tests/translator/output/aws-cn/api_with_stage_tags.json @@ -1,75 +1,75 @@ { "Parameters": { "TagValueParam": { - "Default": "value", + "Default": "value", "Type": "String" } - }, + }, "Resources": { - "MyApiWithStageTagsDeployment5332c373d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithStageTags" - }, - "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", - "StageName": "Stage" - } - }, "MyApiWithStageTags": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, + }, + "version": "1.0" + }, + "paths": {}, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithStageTagsDeployment5332c373d4": { + "Properties": { + "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", + "RestApiId": { + "Ref": "MyApiWithStageTags" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiWithStageTagsProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithStageTagsDeployment5332c373d4" - }, + }, "RestApiId": { "Ref": "MyApiWithStageTags" - }, - "StageName": "Prod", + }, + "StageName": "Prod", "Tags": [ { - "Value": "TagValue1", - "Key": "TagKey1" - }, + "Key": "TagKey1", + "Value": "TagValue1" + }, { - "Value": "", - "Key": "TagKey2" - }, + "Key": "TagKey2", + "Value": "" + }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" - }, + } + }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ] - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_swagger_and_openapi_with_auth.json b/tests/translator/output/aws-cn/api_with_swagger_and_openapi_with_auth.json index 2558c47ca6..246a43aef2 100644 --- a/tests/translator/output/aws-cn/api_with_swagger_and_openapi_with_auth.json +++ b/tests/translator/output/aws-cn/api_with_swagger_and_openapi_with_auth.json @@ -1,28 +1,95 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", + "ExplicitApi": { "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.1.1", + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "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" + } + } + } + } + }, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + }, + "swagger": 2.0 }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment7c4f7dda23": { + "Properties": { + "Description": "RestApi deployment id: 7c4f7dda23acd71e4a653861510d82ad7809e562", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiSomeStageStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment7c4f7dda23" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -42,40 +109,10 @@ "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +121,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,10 +130,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionGetHtmlAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +142,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -114,152 +151,111 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "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": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyCognitoAuth": [] - } - ] - } - } - }, - "securityDefinitions": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - { - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - } - }, - "Name": "some api", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment7c4f7dda23": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7c4f7dda23acd71e4a653861510d82ad7809e562", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", + "MyUserPool": { "Properties": { - "CacheClusterEnabled": true, - "CacheClusterSize": "1.6", - "DeploymentId": { - "Ref": "ExplicitApiDeployment7c4f7dda23" - }, - "RestApiId": { - "Ref": "ExplicitApi" + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } }, - "StageName": "SomeStage", - "Variables": { - "SomeVar": "Value" - } - } + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, + } + } + }, + "/any": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -267,34 +263,37 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, - "Name": "some api", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment614ec93e15": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 614ec93e159f50797f73789c416660484070ee2e", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "CacheClusterEnabled": true, "CacheClusterSize": "1.6", @@ -308,7 +307,8 @@ "Variables": { "SomeVar": "Value" } - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_swagger_authorizer_none.json b/tests/translator/output/aws-cn/api_with_swagger_authorizer_none.json index a850d1674b..8b582c4fbc 100644 --- a/tests/translator/output/aws-cn/api_with_swagger_authorizer_none.json +++ b/tests/translator/output/aws-cn/api_with_swagger_authorizer_none.json @@ -1,311 +1,56 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "/any/cognito": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "NONE": [] } - ] - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { "responses": {}, "security": [ { "NONE": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -313,33 +58,36 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeployment260db70e0f": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 260db70e0f3f53af19cc705a80e50b434facfc0b", "RestApiId": { "Ref": "MyApiWithCognitoAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeployment260db70e0f" @@ -348,63 +96,175 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { + "/lambda-request": { "get": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "passthroughBehavior": "when_no_match", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } + } + } + } + }, + "schemes": [ + "https" + ], + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": 2.0 + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeployment11375c81e1": { + "Properties": { + "Description": "RestApi deployment id: 11375c81e1f1e173c5b9558d011de4088c6212de", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment11375c81e1" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "NONE": [] } - ] - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-token": { + "get": { "responses": {}, "security": [ { "NONE": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -417,180 +277,320 @@ } } ] - } + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaTokenAuthDeployment8433bd70aa": { + "Properties": { + "Description": "RestApi deployment id: 8433bd70aa60c25c2c977feacfaa84dcc96f4f86", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment8433bd70aa" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthDeployment8433bd70aa": { - "Type": "AWS::ApiGateway::Deployment", + "MyFn": { "Properties": { - "Description": "RestApi deployment id: 8433bd70aa60c25c2c977feacfaa84dcc96f4f86", - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment8433bd70aa" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Body": { - "swagger": 2.0, - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "schemes": [ - "https" - ], - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - }, - "passthroughBehavior": "when_no_match" - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - } - }, - "securityDefinitions": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeployment11375c81e1": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 11375c81e1f1e173c5b9558d011de4088c6212de", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment11375c81e1" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_usageplans.json b/tests/translator/output/aws-cn/api_with_usageplans.json index 8e3e14490c..a42005f64b 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans.json +++ b/tests/translator/output/aws-cn/api_with_usageplans.json @@ -1,195 +1,438 @@ { + "Outputs": { + "ApiKey": { + "Description": "Api Key", + "Value": { + "Ref": "ServerlessApiKey" + } + }, + "ApiOneUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "ApiThreeUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "ApiTwoUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "UsagePlan": { + "Description": "Usage Plan physical Id", + "Value": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "UsagePlanKey": { + "Description": "Usage Plan Key", + "Value": { + "Ref": "MyApiTwoUsagePlanKey" + } + } + }, "Resources": { - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", + "MyApiOne": { "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any/path/one": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + }, + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyApiOneDeployment4fc70a300d": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "Description": "RestApi deployment id: 4fc70a300d60c86fcdf4076c1dca96c6195a9aa0", + "RestApiId": { + "Ref": "MyApiOne" }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyFunctionOneApiKeyAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiOneProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" + "DeploymentId": { + "Ref": "MyApiOneDeployment4fc70a300d" }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiThree": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/three": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiThreeDeploymentfa9f73f027": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" + "Description": "RestApi deployment id: fa9f73f0272017527c24cc93cc4440dd4476b9f4", + "RestApiId": { + "Ref": "MyApiThree" }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiThreeDeploymentfa9f73f027" + }, + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", + "MyApiTwoApiKey": { + "DependsOn": [ + "MyApiTwoUsagePlan" + ], "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": { + "Ref": "MyApiTwoProdStage" + } + } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" + }, + "MyApiTwoDeployment03730b64c4": { + "Properties": { + "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", + "RestApiId": { + "Ref": "MyApiTwo" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionTwoRole", - "Arn" - ] + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiTwoProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeployment03730b64c4" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwoUsagePlan": { + "DependsOn": [ + "MyApiTwo" + ], + "Properties": { + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiTwo" + }, + "Stage": { + "Ref": "MyApiTwoProdStage" + } + } + ], + "Description": "Description for usage plan", + "Quota": { + "Limit": 10, + "Offset": 10, + "Period": "MONTH" }, - "Runtime": "nodejs12.x", "Tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "Key": "key1", + "Value": "value1" + }, + { + "Key": "key2", + "Value": "value2" } - ] - } + ], + "Throttle": { + "BurstLimit": 1000, + "RateLimit": 1000 + }, + "UsagePlanName": "SomeRandomName" + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyApiTwoUsagePlanKey": { + "DependsOn": [ + "MyApiTwoApiKey" + ], "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "KeyId": { + "Ref": "MyApiTwoApiKey" + }, + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" + }, + "MyFunctionOne": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionTwoImplicitApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionOneApiKeyAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionTwo" + "Ref": "MyFunctionOne" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/event", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/path/one", { "__ApiId__": { - "Ref": "ServerlessRestApi" + "Ref": "MyApiOne" }, "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionOneApiKeyPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionTwo" + "Ref": "MyFunctionOne" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", { "__ApiId__": { - "Ref": "MyApiTwo" + "Ref": "MyApiOne" }, "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionThree": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -208,13 +451,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionThreeApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionThree" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + { + "__ApiId__": { + "Ref": "MyApiThree" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionThreeRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -227,7 +490,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -238,331 +502,201 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionThreeApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionTwo": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionTwoRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionTwoApiKeyPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionThree" + "Ref": "MyFunctionTwo" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { "__ApiId__": { - "Ref": "MyApiThree" + "Ref": "MyApiTwo" }, "__Stage__": "*" } ] } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/path/one": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiOneDeployment4fc70a300d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 4fc70a300d60c86fcdf4076c1dca96c6195a9aa0", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment4fc70a300d" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiTwoDeployment03730b64c4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionTwoImplicitApiEventPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment03730b64c4" - }, - "RestApiId": { - "Ref": "MyApiTwo" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/event", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiTwoUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", - "DependsOn": [ - "MyApiTwo" - ], + "MyFunctionTwoRole": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiTwo" - }, - "Stage": { - "Ref": "MyApiTwoProdStage" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - } - ], - "Description": "Description for usage plan", - "Quota": { - "Limit": 10, - "Offset": 10, - "Period": "MONTH" + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Key": "key1", - "Value": "value1" - }, - { - "Key": "key2", - "Value": "value2" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Throttle": { - "BurstLimit": 1000, - "RateLimit": 1000 - }, - "UsagePlanName": "SomeRandomName" - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiTwoApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "ServerlessApiKey": { "DependsOn": [ - "MyApiTwoUsagePlan" + "ServerlessUsagePlan" ], "Properties": { "Enabled": true, "StageKeys": [ { "RestApiId": { - "Ref": "MyApiTwo" + "Ref": "MyApiThree" }, "StageName": { - "Ref": "MyApiTwoProdStage" + "Ref": "MyApiThreeProdStage" + } + }, + { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": { + "Ref": "ServerlessRestApiProdStage" } } ] - } - }, - "MyApiTwoUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "DependsOn": [ - "MyApiTwoApiKey" - ], - "Properties": { - "KeyId": { - "Ref": "MyApiTwoApiKey" - }, - "KeyType": "API_KEY", - "UsagePlanId": { - "Ref": "MyApiTwoUsagePlan" - } - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiThree": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/path/three": { + "/path/event": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" - } - }, "responses": {}, "security": [ { "api_key": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } } } }, "securityDefinitions": { "api_key": { - "type": "apiKey", + "in": "header", "name": "x-api-key", - "in": "header" + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiThreeDeploymentfa9f73f027": { - "Type": "AWS::ApiGateway::Deployment", + "ServerlessRestApiDeployment40b50dc688": { "Properties": { - "Description": "RestApi deployment id: fa9f73f0272017527c24cc93cc4440dd4476b9f4", + "Description": "RestApi deployment id: 40b50dc6888e5b556b1073ba4304ec9b550659db", "RestApiId": { - "Ref": "MyApiThree" + "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ServerlessRestApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiThreeDeploymentfa9f73f027" + "Ref": "ServerlessRestApiDeployment40b50dc688" }, "RestApiId": { - "Ref": "MyApiThree" + "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", "DependsOn": [ "MyApiThree", "ServerlessRestApi" @@ -586,37 +720,10 @@ } } ] - } - }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "DependsOn": [ - "ServerlessUsagePlan" - ], - "Properties": { - "Enabled": true, - "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": { - "Ref": "MyApiThreeProdStage" - } - }, - { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": { - "Ref": "ServerlessRestApiProdStage" - } - } - ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "DependsOn": [ "ServerlessApiKey" ], @@ -628,115 +735,8 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/event": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ServerlessRestApiDeployment40b50dc688": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 40b50dc6888e5b556b1073ba4304ec9b550659db", - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment40b50dc688" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - } - }, - "Outputs": { - "ApiOneUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "ApiTwoUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "ApiThreeUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "UsagePlan": { - "Description": "Usage Plan physical Id", - "Value": { - "Ref": "MyApiTwoUsagePlan" - } - }, - "UsagePlanKey": { - "Description": "Usage Plan Key", - "Value": { - "Ref": "MyApiTwoUsagePlanKey" - } - }, - "ApiKey": { - "Description": "Api Key", - "Value": { - "Ref": "ServerlessApiKey" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_usageplans_intrinsics.json b/tests/translator/output/aws-cn/api_with_usageplans_intrinsics.json index c9a6c42308..1273aff861 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans_intrinsics.json +++ b/tests/translator/output/aws-cn/api_with_usageplans_intrinsics.json @@ -1,26 +1,26 @@ { + "Conditions": { + "C1": { + "Fn::Equals": [ + true, + true + ] + } + }, "Outputs": { - "ApiTwoUrl": { + "ApiOneUrl": { "Description": "API endpoint URL for Prod environment", "Value": { - "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } }, - "ApiOneUrl": { + "ApiTwoUrl": { "Description": "API endpoint URL for Prod environment", "Value": { - "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } } }, - "Conditions": { - "C1": { - "Fn::Equals": [ - true, - true - ] - } - }, "Parameters": { "UsagePlanType": { "Default": "PER_API", @@ -28,215 +28,337 @@ } }, "Resources": { - "MyApiTwoUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "MyApiOne": { + "Condition": "C1", "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "MyApiTwoApiKey" + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + } }, - "UsagePlanId": { - "Ref": "MyApiTwoUsagePlan" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } }, - "DependsOn": [ - "MyApiTwoApiKey" - ] + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiOneUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiOneApiKey": { + "Condition": "C1", + "DependsOn": [ + "MyApiOneUsagePlan" + ], "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } } ] }, + "Type": "AWS::ApiGateway::ApiKey" + }, + "MyApiOneDeploymentd8cca8c82b": { + "Condition": "C1", + "Properties": { + "Description": "RestApi deployment id: d8cca8c82bb70492b08f8ad3e95b75b30fb6ce14", + "RestApiId": { + "Ref": "MyApiOne" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeploymentd8cca8c82b" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiOneUsagePlan": { + "Condition": "C1", "DependsOn": [ "MyApiOne" ], - "Condition": "C1" - }, - "MyApiTwoUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", "Properties": { "ApiStages": [ { "ApiId": { - "Ref": "MyApiTwo" + "Ref": "MyApiOne" }, "Stage": { - "Ref": "MyApiTwoProdStage" + "Ref": "MyApiOneProdStage" } } ] }, - "DependsOn": [ - "MyApiTwo" - ] - }, - "MyApiTwoDeploymenta997b9e562": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "Description": "RestApi deployment id: a997b9e562a05ea9cb87782748d6df042f6a82d4" - } + "Type": "AWS::ApiGateway::UsagePlan" }, "MyApiOneUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "Condition": "C1", + "DependsOn": [ + "MyApiOneApiKey" + ], "Properties": { - "KeyType": "API_KEY", "KeyId": { "Ref": "MyApiOneApiKey" }, + "KeyType": "API_KEY", "UsagePlanId": { "Ref": "MyApiOneUsagePlan" } }, - "DependsOn": [ - "MyApiOneApiKey" - ], - "Condition": "C1" - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeploymenta997b9e562" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } + "Type": "AWS::ApiGateway::UsagePlanKey" }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiTwo": { "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeploymentd8cca8c82b" + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + } }, - "RestApiId": { - "Ref": "MyApiOne" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Prod" + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } }, - "Condition": "C1" + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiOneApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyApiTwoApiKey": { + "DependsOn": [ + "MyApiTwoUsagePlan" + ], "Properties": { "Enabled": true, "StageKeys": [ { "RestApiId": { - "Ref": "MyApiOne" + "Ref": "MyApiTwo" }, "StageName": { - "Ref": "MyApiOneProdStage" + "Ref": "MyApiTwoProdStage" } } ] }, - "DependsOn": [ - "MyApiOneUsagePlan" - ], - "Condition": "C1" + "Type": "AWS::ApiGateway::ApiKey" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyApiTwoDeploymenta997b9e562": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: a997b9e562a05ea9cb87782748d6df042f6a82d4", + "RestApiId": { + "Ref": "MyApiTwo" + } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiOneDeploymentd8cca8c82b": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiTwoProdStage": { "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeploymenta997b9e562" + }, "RestApiId": { - "Ref": "MyApiOne" + "Ref": "MyApiTwo" }, - "Description": "RestApi deployment id: d8cca8c82bb70492b08f8ad3e95b75b30fb6ce14" + "StageName": "Prod" }, - "Condition": "C1" + "Type": "AWS::ApiGateway::Stage" }, - "MyApiTwoApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyApiTwoUsagePlan": { + "DependsOn": [ + "MyApiTwo" + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } } ] }, + "Type": "AWS::ApiGateway::UsagePlan" + }, + "MyApiTwoUsagePlanKey": { "DependsOn": [ - "MyApiTwoUsagePlan" - ] + "MyApiTwoApiKey" + ], + "Properties": { + "KeyId": { + "Ref": "MyApiTwoApiKey" + }, + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" + }, + "MyFunctionOne": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionOne" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiOne" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionTwoRole", @@ -246,41 +368,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionTwo" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiTwo" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -293,138 +411,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } }, - "Condition": "C1" - }, - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_three.json b/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_three.json index 3f37e5bf0d..8e637d0f02 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_three.json +++ b/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_three.json @@ -14,8 +14,229 @@ } }, "Resources": { + "MyApiOne": { + "Condition": "C1", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Delete" + }, + "MyApiOneDeployment7997029260": { + "Condition": "C1", + "Properties": { + "Description": "RestApi deployment id: 79970292604071da8105ffd8503f82af32b30550", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Delete" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment7997029260" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Delete" + }, + "MyApiThree": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/three": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiThreeDeploymentfa9f73f027": { + "Properties": { + "Description": "RestApi deployment id: fa9f73f0272017527c24cc93cc4440dd4476b9f4", + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiThreeDeploymentfa9f73f027" + }, + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Condition": "C2", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Snapshot" + }, + "MyApiTwoDeployment03730b64c4": { + "Condition": "C2", + "Properties": { + "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Snapshot" + }, + "MyApiTwoProdStage": { + "Condition": "C2", + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeployment03730b64c4" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Snapshot" + }, "MyFunctionOne": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -34,13 +255,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -53,7 +294,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -64,31 +306,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", + "MyFunctionThree": { "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -96,7 +317,7 @@ "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionTwoRole", + "MyFunctionThreeRole", "Arn" ] }, @@ -107,13 +328,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionThreeApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionThree" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + { + "__ApiId__": { + "Ref": "MyApiThree" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionThreeRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -126,7 +367,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -137,31 +379,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", - { - "__ApiId__": { - "Ref": "MyApiTwo" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionThree": { - "Type": "AWS::Lambda::Function", + "MyFunctionTwo": { "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -169,7 +390,7 @@ "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionThreeRole", + "MyFunctionTwoRole", "Arn" ] }, @@ -180,13 +401,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionThreeRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + { + "__ApiId__": { + "Ref": "MyApiTwo" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionTwoRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -199,7 +440,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -210,184 +452,86 @@ "Value": "SAM" } ] - } - }, - "MyFunctionThreeApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionThree" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", - { - "__ApiId__": { - "Ref": "MyApiThree" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiOneDeployment7997029260": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "Description": "RestApi deployment id: 79970292604071da8105ffd8503f82af32b30550", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment7997029260" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "ServerlessApiKey": { "DependsOn": [ - "MyApiOne", - "MyApiTwo", - "MyApiThree" + "ServerlessUsagePlan" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiThree" }, - "Stage": { + "StageName": { "Ref": "MyApiThreeProdStage" } } ] - } - }, - "ServerlessApiKey": { + }, "Type": "AWS::ApiGateway::ApiKey", + "UpdateReplacePolicy": "Snapshot" + }, + "ServerlessUsagePlan": { "DependsOn": [ - "ServerlessUsagePlan" + "MyApiOne", + "MyApiTwo", + "MyApiThree" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiOne" }, - "StageName": { + "Stage": { "Ref": "MyApiOneProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiThree" }, - "StageName": { + "Stage": { "Ref": "MyApiThreeProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan", + "UpdateReplacePolicy": "Snapshot" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "DependsOn": [ "ServerlessApiKey" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { "KeyId": { "Ref": "ServerlessApiKey" @@ -396,153 +540,9 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiTwoDeployment03730b64c4": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment03730b64c4" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } - }, - "MyApiThree": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/three": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiThreeDeploymentfa9f73f027": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: fa9f73f0272017527c24cc93cc4440dd4476b9f4", - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": "Stage" - } - }, - "MyApiThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiThreeDeploymentfa9f73f027" - }, - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey", + "UpdateReplacePolicy": "Snapshot" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_two.json b/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_two.json index bf555befa1..267272004a 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_two.json +++ b/tests/translator/output/aws-cn/api_with_usageplans_shared_attributes_two.json @@ -24,8 +24,159 @@ } }, "Resources": { + "MyApiOne": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiOneDeployment7997029260": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "Description": "RestApi deployment id: 79970292604071da8105ffd8503f82af32b30550", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment7997029260" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoDeployment03730b64c4": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiTwoProdStage": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeployment03730b64c4" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionOne": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -44,13 +195,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -63,7 +234,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -74,31 +246,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -117,13 +268,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionTwoApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + { + "__ApiId__": { + "Ref": "MyApiTwo" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -136,7 +307,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -147,170 +319,73 @@ "Value": "SAM" } ] - } - }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", - { - "__ApiId__": { - "Ref": "MyApiTwo" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "DeletionPolicy": "Delete", - "Condition": "C1", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiOneDeployment7997029260": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C1", - "DeletionPolicy": "Delete", - "Properties": { - "Description": "RestApi deployment id: 79970292604071da8105ffd8503f82af32b30550", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C1", - "DeletionPolicy": "Delete", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment7997029260" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", - "DependsOn": [ - "MyApiOne", - "MyApiTwo" - ], + "ServerlessApiKey": { "Condition": "SharedUsagePlanCondition", "DeletionPolicy": "Retain", + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "DependsOn": [ - "ServerlessUsagePlan" - ], + "ServerlessUsagePlan": { "Condition": "SharedUsagePlanCondition", "DeletionPolicy": "Retain", + "DependsOn": [ + "MyApiOne", + "MyApiTwo" + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiOne" }, - "StageName": { + "Stage": { "Ref": "MyApiOneProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "Condition": "SharedUsagePlanCondition", + "DeletionPolicy": "Retain", "DependsOn": [ "ServerlessApiKey" ], - "Condition": "SharedUsagePlanCondition", - "DeletionPolicy": "Retain", "Properties": { "KeyId": { "Ref": "ServerlessApiKey" @@ -319,83 +394,8 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "DeletionPolicy": "Retain", - "Condition": "C2", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiTwoDeployment03730b64c4": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C2", - "DeletionPolicy": "Retain", - "Properties": { - "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C2", - "DeletionPolicy": "Retain", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment03730b64c4" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_1.json b/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_1.json index 8305db4dfa..976012570b 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_1.json +++ b/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_1.json @@ -1,71 +1,134 @@ { "Resources": { - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiOne": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiOne" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "Stage": { - "Ref": "MyApiOneProdStage" + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } } }, - { - "ApiId": { - "Ref": "MyApiTwo" - }, - "Stage": { - "Ref": "MyApiTwoProdStage" + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - ] + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } }, - "DependsOn": [ - "MyApiOne", - "MyApiTwo" - ] + "Type": "AWS::ApiGateway::RestApi" }, "MyApiOneDeployment7997029260": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 79970292604071da8105ffd8503f82af32b30550", "RestApiId": { "Ref": "MyApiOne" }, - "Description": "RestApi deployment id: 79970292604071da8105ffd8503f82af32b30550", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyApiOneProdStage": { "Properties": { - "Enabled": true, - "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiOne" + "DeploymentId": { + "Ref": "MyApiOneDeployment7997029260" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "StageName": { - "Ref": "MyApiOneProdStage" + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } } }, - { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": { - "Ref": "MyApiTwoProdStage" + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - ] + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } }, - "DependsOn": [ - "ServerlessUsagePlan" - ] + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoDeployment03730b64c4": { + "Properties": { + "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiTwoDeployment03730b64c4" @@ -74,35 +137,55 @@ "Ref": "MyApiTwo" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionOne": { "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment7997029260" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "RestApiId": { - "Ref": "MyApiOne" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiTwoDeployment03730b64c4": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionOneApiKeyPermissionProd": { "Properties": { - "RestApiId": { - "Ref": "MyApiTwo" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" }, - "Description": "RestApi deployment id: 03730b64c486cc490deefb3b8225244b0fe85d34", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionOneRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -115,62 +198,27 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "ServerlessApiKey" - }, - "UsagePlanId": { - "Ref": "ServerlessUsagePlan" - } }, - "DependsOn": [ - "ServerlessApiKey" - ] - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiOne" - } - } - ] - } - } + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionTwoRole", @@ -180,38 +228,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionTwo" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiTwo" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -224,136 +271,89 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessApiKey": { + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": { + "Ref": "MyApiOneProdStage" } }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + { + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": { + "Ref": "MyApiTwoProdStage" } } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessUsagePlan": { + "DependsOn": [ + "MyApiOne", + "MyApiTwo" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiOne" + }, + "Stage": { + "Ref": "MyApiOneProdStage" } }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + { + "ApiId": { + "Ref": "MyApiTwo" + }, + "Stage": { + "Ref": "MyApiTwoProdStage" } } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + ] + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", + "ServerlessUsagePlanKey": { + "DependsOn": [ + "ServerlessApiKey" + ], "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] + "KeyId": { + "Ref": "ServerlessApiKey" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "ServerlessUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_2.json b/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_2.json index ee9bdd13e6..b4ca2870d6 100644 --- a/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_2.json +++ b/tests/translator/output/aws-cn/api_with_usageplans_shared_no_side_effect_2.json @@ -1,59 +1,121 @@ { "Resources": { - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiFour": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiFour" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "Stage": { - "Ref": "MyApiFourProdStage" + "version": "1.0" + }, + "paths": { + "/path/four": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionFour.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiFourDeploymentf92b67251a": { + "Properties": { + "Description": "RestApi deployment id: f92b67251a066bec5ee160eeff9c5ab747d9f417", + "RestApiId": { + "Ref": "MyApiFour" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiFourProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiFourDeploymentf92b67251a" + }, + "RestApiId": { + "Ref": "MyApiFour" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionFour": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionFourRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyApiFour" - ] + "Type": "AWS::Lambda::Function" }, "MyFunctionFourApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionFour" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/four", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiFour" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiFourDeploymentf92b67251a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiFour" - }, - "Description": "RestApi deployment id: f92b67251a066bec5ee160eeff9c5ab747d9f417", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionFourRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -66,36 +128,25 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "ServerlessApiKey" - }, - "UsagePlanId": { - "Ref": "ServerlessUsagePlan" - } }, - "DependsOn": [ - "ServerlessApiKey" - ] + "Type": "AWS::IAM::Role" }, "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { "Enabled": true, "StageKeys": [ @@ -109,91 +160,40 @@ } ] }, - "DependsOn": [ - "ServerlessUsagePlan" - ] - }, - "MyApiFour": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/four": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionFour.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "Type": "AWS::ApiGateway::ApiKey" }, - "MyFunctionFour": { - "Type": "AWS::Lambda::Function", + "ServerlessUsagePlan": { + "DependsOn": [ + "MyApiFour" + ], "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionFourRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "ApiStages": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "ApiId": { + "Ref": "MyApiFour" + }, + "Stage": { + "Ref": "MyApiFourProdStage" + } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyApiFourProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ServerlessUsagePlanKey": { + "DependsOn": [ + "ServerlessApiKey" + ], "Properties": { - "DeploymentId": { - "Ref": "MyApiFourDeploymentf92b67251a" - }, - "RestApiId": { - "Ref": "MyApiFour" + "KeyId": { + "Ref": "ServerlessApiKey" }, - "StageName": "Prod" - } + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "ServerlessUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/api_with_xray_tracing.json b/tests/translator/output/aws-cn/api_with_xray_tracing.json index 34acf45978..bbad7dce28 100644 --- a/tests/translator/output/aws-cn/api_with_xray_tracing.json +++ b/tests/translator/output/aws-cn/api_with_xray_tracing.json @@ -1,37 +1,33 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "HtmlApiDeploymentf117c932f7" @@ -41,76 +37,80 @@ }, "StageName": "Prod", "TracingEnabled": true - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "HtmlFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/application_preparing_state.json b/tests/translator/output/aws-cn/application_preparing_state.json index 92fe7cc8d7..9129453a05 100644 --- a/tests/translator/output/aws-cn/application_preparing_state.json +++ b/tests/translator/output/aws-cn/application_preparing_state.json @@ -1,24 +1,24 @@ { "Resources": { "PreparingApplication": { - "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" }, { - "Value": "preparing", - "Key": "serverlessrepo:applicationId" + "Key": "serverlessrepo:applicationId", + "Value": "preparing" }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" } } } diff --git a/tests/translator/output/aws-cn/application_with_intrinsics.json b/tests/translator/output/aws-cn/application_with_intrinsics.json index 314a99e302..59ac13f2da 100644 --- a/tests/translator/output/aws-cn/application_with_intrinsics.json +++ b/tests/translator/output/aws-cn/application_with_intrinsics.json @@ -1,76 +1,76 @@ { - "Parameters": { - "ApplicationIdParam": { - "Default": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Type": "String" - }, - "VersionParam": { - "Default": "1.0.0", - "Type": "String" - } - }, "Mappings": { "ApplicationLocations": { + "ap-southeast-1": { + "ApplicationId": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world", + "Version": "1.0.1" + }, "cn-north-1": { - "Version": "1.0.2", - "ApplicationId": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world" - }, + "ApplicationId": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world", + "Version": "1.0.2" + }, "us-gov-west-1": { - "Version": "1.0.3", - "ApplicationId": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world" - }, - "ap-southeast-1": { - "Version": "1.0.1", - "ApplicationId": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world" + "ApplicationId": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world", + "Version": "1.0.3" } } - }, + }, + "Parameters": { + "ApplicationIdParam": { + "Default": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Type": "String" + }, + "VersionParam": { + "Default": "1.0.0", + "Type": "String" + } + }, "Resources": { "ApplicationFindInMap": { - "Type": "AWS::CloudFormation::Stack", "Properties": { "NotificationARNs": [ { "Ref": "Sns" } - ], - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, "ApplicationRefParameter": { - "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "1.0.0", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.0" } - ] - } - }, + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, "Sns": { "Type": "AWS::SNS::Topic" } diff --git a/tests/translator/output/aws-cn/basic_application.json b/tests/translator/output/aws-cn/basic_application.json index 058e8037e5..96a827f8e5 100644 --- a/tests/translator/output/aws-cn/basic_application.json +++ b/tests/translator/output/aws-cn/basic_application.json @@ -2,99 +2,99 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Resources": { - "NormalApplication": { - "Type": "AWS::CloudFormation::Stack", + "ApplicationWithCondition": { + "Condition": "TestCondition", "Properties": { - "NotificationARNs": [ - "arn:aws:sns:us-east-1:123456789012:sns-arn" - ], - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", - "TimeoutInMinutes": 15, - "Parameters": { - "IdentityNameParameter": "IdentityName" - }, "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "TagValue", - "Key": "TagName" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, - "BasicApplication": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "ApplicationWithLocationUrl": { "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "TagName2", + "Value": "TagValue2" } - ] - } - }, - "ApplicationWithLocationUrl": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "BasicApplication": { "Properties": { - "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "TagValue2", - "Key": "TagName2" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, - "ApplicationWithCondition": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "NormalApplication": { "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "NotificationARNs": [ + "arn:aws:sns:us-east-1:123456789012:sns-arn" + ], + "Parameters": { + "IdentityNameParameter": "IdentityName" + }, "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "TagName", + "Value": "TagValue" } - ] - }, - "Condition": "TestCondition" + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TimeoutInMinutes": 15 + }, + "Type": "AWS::CloudFormation::Stack" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/basic_function.json b/tests/translator/output/aws-cn/basic_function.json index f3d2b18916..79d8c4c2ab 100644 --- a/tests/translator/output/aws-cn/basic_function.json +++ b/tests/translator/output/aws-cn/basic_function.json @@ -1,459 +1,459 @@ { "Parameters": { - "SomeParameter": { - "Default": "param", - "Type": "String" - }, "SomeOtherParameter": { - "Default": "otherparam", + "Default": "otherparam", + "Type": "String" + }, + "SomeParameter": { + "Default": "param", "Type": "String" } - }, + }, "Resources": { - "FunctionWithInlineCode": { - "Type": "AWS::Lambda::Function", + "CompleteFunction": { "Properties": { - "TracingConfig": { - "Mode": "Active" - }, "Code": { - "ZipFile": "hello world" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Starter Lambda Function", + "Environment": { + "Variables": { + "Name": "Value", + "Name2": "Value2" + } + }, + "FunctionName": "MyAwesomeFunction", + "Handler": "hello.handler", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", + ], + "Timeout": 60, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", + { + "Ref": "SomeParameter" + }, + { + "Ref": "SomeOtherParameter" + } + ] + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithCodeUriObject": { + "Properties": { + "Code": { + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "1" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithInlineCodeRole", + "FunctionWithCodeUriObjectRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithCodeUriObjectRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithInlineCode": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + "ZipFile": "hello world" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "FunctionWithInlineCodeRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "TracingConfig": { + "Mode": "Active" + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithInlineCodeRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithPolicies": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", + "FunctionWithPoliciesRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithPoliciesRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithPolicyDocument": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "FunctionWithPolicyDocumentRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithCodeUriObjectRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithPolicyDocumentRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Path": "/", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Policies": [ { - "PolicyName": "root", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Allow" + "Action": [ + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "ec2.amazonaws.com" - ] - } - } - ] - } - } - }, - "CompleteFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Starter Lambda Function", - "VpcConfig": { - "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08", - { - "Ref": "SomeParameter" - }, - { - "Ref": "SomeOtherParameter" - } - ], - "SecurityGroupIds": [ - "sg-edcd9784" - ] - }, + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Environment": { - "Variables": { - "Name2": "Value2", - "Name": "Value" - } - }, - "Handler": "hello.handler", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "Runtime": "python2.7", - "FunctionName": "MyAwesomeFunction" - } - }, - "FunctionWithCodeUriObject": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithRoleRef": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": "1" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithCodeUriObjectRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithTracing": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithTracingRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "TracingConfig": { + "Mode": "Active" + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithTracingRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithInlineCodeRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithTracingRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess" + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "ec2.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionWithTracing": { - "Type": "AWS::Lambda::Function", - "Properties": { - "TracingConfig": { - "Mode": "Active" - }, - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithTracingRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + ], + "Version": "2012-10-17" + }, + "Path": "/", "Policies": [ { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", "PolicyDocument": { "Statement": [ { - "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" + "Action": "*", + "Effect": "Allow", + "Resource": "*" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "root" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/basic_function_with_tags.json b/tests/translator/output/aws-cn/basic_function_with_tags.json index 119f925f35..60998c5c3e 100644 --- a/tests/translator/output/aws-cn/basic_function_with_tags.json +++ b/tests/translator/output/aws-cn/basic_function_with_tags.json @@ -1,5 +1,5 @@ { - "AWSTemplateFormatVersion": "2010-09-09", + "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "TagValueParam": { "Default": "Val", @@ -7,108 +7,107 @@ } }, "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", + "AlexaSkillFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" }, { - "Value": "TagValue1", - "Key": "TagKey1" + "Key": "TagKey1", + "Value": "TagValue1" }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ], - + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "TagValue1", - "Key": "TagKey1" - }, + "Key": "TagKey1", + "Value": "TagValue1" + }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/basic_function_withimageuri.json b/tests/translator/output/aws-cn/basic_function_withimageuri.json index 894fbb717c..3adab3cccb 100644 --- a/tests/translator/output/aws-cn/basic_function_withimageuri.json +++ b/tests/translator/output/aws-cn/basic_function_withimageuri.json @@ -1,54 +1,61 @@ { "Parameters": { - "SomeParameter": { - "Type": "String", - "Default": "param" - }, "SomeOtherParameter": { - "Type": "String", - "Default": "otherparam" + "Default": "otherparam", + "Type": "String" + }, + "SomeParameter": { + "Default": "param", + "Type": "String" } }, "Resources": { - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "CompleteImageFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": { - "Service": [ - "ec2.amazonaws.com" - ] - }, - "Action": [ - "sts:AssumeRole" - ] - } - ] + "Code": { + "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, - "Path": "/", - "Policies": [ + "Description": "Starter Lambda Function", + "Environment": { + "Variables": { + "Name": "Value", + "Name2": "Value2" + } + }, + "FunctionName": "MyAwesomeFunction", + "ImageConfig": { + "Command": "/bin/sh", + "EntryPoint": "echo hello world!", + "WorkingDirectory": "/var/task" + }, + "PackageType": "Image", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Tags": [ { - "PolicyName": "root", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": "*", - "Resource": "*" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ] - } + ], + "Timeout": 60, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", + { + "Ref": "SomeParameter" + }, + { + "Ref": "SomeOtherParameter" + } + ] + } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithPolicies": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" @@ -56,7 +63,7 @@ "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "MinimalImageFunctionRole", + "FunctionWithPoliciesRole", "Arn" ] }, @@ -66,13 +73,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunctionRole": { - "Type": "AWS::IAM::Role", + "FunctionWithPoliciesRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -85,10 +91,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" ], "Tags": [ { @@ -96,10 +104,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalImageFunctionPackageTypeAndImageConfig": { - "Type": "AWS::Lambda::Function", + "FunctionWithPolicyDocument": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" @@ -107,7 +115,7 @@ "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "MinimalImageFunctionPackageTypeAndImageConfigRole", + "FunctionWithPolicyDocumentRole", "Arn" ] }, @@ -116,19 +124,13 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "ImageConfig": { - "WorkingDirectory": "/var/task", - "Command": "/bin/sh", - "EntryPoint": "echo hello world!" - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunctionPackageTypeAndImageConfigRole": { - "Type": "AWS::IAM::Role", + "FunctionWithPolicyDocumentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -141,74 +143,93 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ] + }, + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0" + } + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "CompleteImageFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithRoleRef": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, "PackageType": "Image", - "Description": "Starter Lambda Function", - "FunctionName": "MyAwesomeFunction", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "VpcConfig": { - "SecurityGroupIds": [ - "sg-edcd9784" - ], - "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08", - { - "Ref": "SomeParameter" - }, - { - "Ref": "SomeOtherParameter" - } + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" ] }, - "Environment": { - "Variables": { - "Name": "Value", - "Name2": "Value2" + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalImageFunction": { + "Properties": { + "Code": { + "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" + }, + "PackageType": "Image", + "Role": { + "Fn::GetAtt": [ + "MinimalImageFunctionRole", + "Arn" + ] }, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "ImageConfig": { - "WorkingDirectory": "/var/task", - "Command": "/bin/sh", - "EntryPoint": "echo hello world!" - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + "MinimalImageFunctionPackageTypeAndImageConfig": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, + "ImageConfig": { + "Command": "/bin/sh", + "EntryPoint": "echo hello world!", + "WorkingDirectory": "/var/task" + }, "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "MinimalImageFunctionPackageTypeAndImageConfigRole", "Arn" ] }, @@ -218,13 +239,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + "MinimalImageFunctionPackageTypeAndImageConfigRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -237,11 +257,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { @@ -249,34 +269,42 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + "MinimalImageFunctionRole": { "Properties": { - "Code": { - "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" - }, - "PackageType": "Image", - "Role": { - "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -285,59 +313,31 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "ec2.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Path": "/", "Policies": [ { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", "PolicyDocument": { "Statement": [ { - "Action": [ - "dynamodb:*" - ], + "Action": "*", "Effect": "Allow", "Resource": "*" } - ] - } - } - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" - }, - "PackageType": "Image", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" + ], + "Version": "2012-10-17" + }, + "PolicyName": "root" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/basic_layer.json b/tests/translator/output/aws-cn/basic_layer.json index f7e9238f58..94901714e4 100644 --- a/tests/translator/output/aws-cn/basic_layer.json +++ b/tests/translator/output/aws-cn/basic_layer.json @@ -2,7 +2,7 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "beta", + "beta", "beta" ] } @@ -14,94 +14,94 @@ } }, "Resources": { - "LayerWithCondition7c655e10ea": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "CompleteLayer5d71a60e81": { + "DeletionPolicy": "Retain", "Properties": { + "CompatibleRuntimes": [ + "python3.6", + "python2.7" + ], "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "LayerWithCondition" - }, - "Condition": "TestCondition" - }, - "MinimalLayer0c7f96cce7": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "Description": "Starter Lambda Layer", + "LayerName": "MyAwesomeLayer", + "LicenseInfo": "License information" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithArchitecturesab56a78493": { + "DeletionPolicy": "Retain", "Properties": { + "CompatibleArchitectures": [ + "x86_64", + "arm64" + ], "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MinimalLayer" - } - }, - "CompleteLayer5d71a60e81": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "LayerName": "LayerWithArchitectures" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithCaseInsensitiveRetentionPolicyead52a491d": { + "DeletionPolicy": "Delete", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MyAwesomeLayer", - "Description": "Starter Lambda Layer", - "LicenseInfo": "License information", - "CompatibleRuntimes": [ - "python3.6", - "python2.7" - ] - } - }, - "LayerWithContentUriObjectbdbf1b82ac": { - "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", + }, + "LayerName": "LayerWithCaseInsensitiveRetentionPolicy" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithCondition7c655e10ea": { + "Condition": "TestCondition", + "DeletionPolicy": "Retain", "Properties": { "Content": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": "v1" - }, - "LayerName": "LayerWithContentUriObject" - } + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithCondition" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithCaseInsensitiveRetentionPolicyead52a491d": { + "LayerWithContentUriObjectbdbf1b82ac": { "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "v1" }, - "LayerName": "LayerWithCaseInsensitiveRetentionPolicy" - } + "LayerName": "LayerWithContentUriObject" + }, + "Type": "AWS::Lambda::LayerVersion" }, "LayerWithRetentionPolicyParamcc64815342": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, "LayerName": "LayerWithRetentionPolicyParam" - } - }, - "LayerWithArchitecturesab56a78493": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "MinimalLayer0c7f96cce7": { + "DeletionPolicy": "Retain", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "CompatibleArchitectures": [ - "x86_64", - "arm64" - ], - "LayerName": "LayerWithArchitectures" - } + }, + "LayerName": "MinimalLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } } diff --git a/tests/translator/output/aws-cn/cloudwatch_logs_with_ref.json b/tests/translator/output/aws-cn/cloudwatch_logs_with_ref.json index 029fab42e6..75c77bae8d 100644 --- a/tests/translator/output/aws-cn/cloudwatch_logs_with_ref.json +++ b/tests/translator/output/aws-cn/cloudwatch_logs_with_ref.json @@ -1,5 +1,6 @@ { "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Example CloudWatch Logs + Lambda", "Parameters": { "FilterPattern": { "Default": "My filter pattern", @@ -11,28 +12,7 @@ } }, "Resources": { - "TriggeredFunctionCWLogEvent": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Fn::GetAtt": [ - "TriggeredFunction", - "Arn" - ] - }, - "FilterPattern": { - "Ref": "FilterPattern" - }, - "LogGroupName": { - "Ref": "LogGroupName" - } - }, - "DependsOn": [ - "TriggeredFunctionCWLogEventPermission" - ] - }, "TriggeredFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -49,50 +29,40 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", + "TriggeredFunctionCWLogEvent": { + "DependsOn": [ + "TriggeredFunctionCWLogEventPermission" + ], "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "DestinationArn": { + "Fn::GetAtt": [ + "TriggeredFunction", + "Arn" ] + }, + "FilterPattern": { + "Ref": "FilterPattern" + }, + "LogGroupName": { + "Ref": "LogGroupName" } - } + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "TriggeredFunctionCWLogEventPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "TriggeredFunction" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -103,8 +73,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "Example CloudWatch Logs + Lambda" + } } diff --git a/tests/translator/output/aws-cn/cloudwatchevent.json b/tests/translator/output/aws-cn/cloudwatchevent.json index b62317f54d..0919448878 100644 --- a/tests/translator/output/aws-cn/cloudwatchevent.json +++ b/tests/translator/output/aws-cn/cloudwatchevent.json @@ -1,185 +1,185 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json b/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json index d761fc5e07..672502744c 100644 --- a/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json +++ b/tests/translator/output/aws-cn/cloudwatchevent_intrinsics.json @@ -1,14 +1,4 @@ { - "Parameters": { - "PathA": { - "Type": "String", - "Default": "SomeInputPath" - }, - "PathB": { - "Type": "String", - "Default": "AnotherInputPath" - } - }, "Conditions": { "PathCondition": { "Fn::Equals": [ @@ -17,9 +7,18 @@ ] } }, + "Parameters": { + "PathA": { + "Default": "SomeInputPath", + "Type": "String" + }, + "PathB": { + "Default": "AnotherInputPath", + "Type": "String" + } + }, "Resources": { "LambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -39,40 +38,10 @@ "Value": "SAM" } ] - } - }, - "LambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "LambdaFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { "EventBusName": { "Fn::Join": [ @@ -125,10 +94,10 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "LambdaFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -141,7 +110,38 @@ "Arn" ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "LambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/cloudwatchlog.json b/tests/translator/output/aws-cn/cloudwatchlog.json index f113442827..38eb260e42 100644 --- a/tests/translator/output/aws-cn/cloudwatchlog.json +++ b/tests/translator/output/aws-cn/cloudwatchlog.json @@ -1,23 +1,6 @@ { "Resources": { - "TriggeredFunctionCWLogEvent": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Fn::GetAtt": [ - "TriggeredFunction", - "Arn" - ] - }, - "FilterPattern": "My filter pattern", - "LogGroupName": "MyCWLogGroup" - }, - "DependsOn": [ - "TriggeredFunctionCWLogEventPermission" - ] - }, "TriggeredFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -34,50 +17,36 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", + "TriggeredFunctionCWLogEvent": { + "DependsOn": [ + "TriggeredFunctionCWLogEventPermission" + ], "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "DestinationArn": { + "Fn::GetAtt": [ + "TriggeredFunction", + "Arn" ] - } - } + }, + "FilterPattern": "My filter pattern", + "LogGroupName": "MyCWLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "TriggeredFunctionCWLogEventPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "TriggeredFunction" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -86,7 +55,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/cognito_userpool_with_event.json b/tests/translator/output/aws-cn/cognito_userpool_with_event.json index 711109b4b7..68ace04e8e 100644 --- a/tests/translator/output/aws-cn/cognito_userpool_with_event.json +++ b/tests/translator/output/aws-cn/cognito_userpool_with_event.json @@ -1,53 +1,6 @@ { "Resources": { - "UserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "LambdaConfig": { - "PreSignUp": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - }, - "PostConfirmation": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - }, - "VerifyAuthChallengeResponse": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - } - }, - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ], - "UserAttributeUpdateSettings": { - "AttributesRequireVerificationBeforeUpdate": [ - "email" - ] - }, - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName" - } - }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -67,13 +20,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionCognitoPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "UserPool", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -86,7 +54,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -97,23 +66,54 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionCognitoPermission": { - "Type": "AWS::Lambda::Permission", + "UserPool": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" + "LambdaConfig": { + "PostConfirmation": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + }, + "PreSignUp": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + }, + "VerifyAuthChallengeResponse": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + } }, - "Principal": "cognito-idp.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "UserPool", - "Arn" + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserAttributeUpdateSettings": { + "AttributesRequireVerificationBeforeUpdate": [ + "email" ] - } - } + }, + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/congito_userpool_with_sms_configuration.json b/tests/translator/output/aws-cn/congito_userpool_with_sms_configuration.json index 3c37f2d4ff..338ce09389 100644 --- a/tests/translator/output/aws-cn/congito_userpool_with_sms_configuration.json +++ b/tests/translator/output/aws-cn/congito_userpool_with_sms_configuration.json @@ -1,32 +1,6 @@ { "Resources": { - "MyCognitoUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "LambdaConfig": { - "PreSignUp": { - "Fn::GetAtt": [ - "HelloWorldFunction", - "Arn" - ] - } - }, - "SmsConfiguration": { - "SnsCallerArn": { - "Fn::GetAtt": [ - "UserPoolRole", - "Arn" - ] - }, - "ExternalId": { - "Ref": "ExternalId" - } - }, - "UserPoolName": "PreSignup" - } - }, "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -46,13 +20,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionCognitoPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyCognitoUserPool", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +54,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,23 +66,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "HelloWorldFunctionCognitoPermission": { - "Type": "AWS::Lambda::Permission", + "MyCognitoUserPool": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HelloWorldFunction" + "LambdaConfig": { + "PreSignUp": { + "Fn::GetAtt": [ + "HelloWorldFunction", + "Arn" + ] + } }, - "Principal": "cognito-idp.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "MyCognitoUserPool", - "Arn" - ] - } - } + "SmsConfiguration": { + "ExternalId": { + "Ref": "ExternalId" + }, + "SnsCallerArn": { + "Fn::GetAtt": [ + "UserPoolRole", + "Arn" + ] + } + }, + "UserPoolName": "PreSignup" + }, + "Type": "AWS::Cognito::UserPool" } } } diff --git a/tests/translator/output/aws-cn/connector_api_to_function.json b/tests/translator/output/aws-cn/connector_api_to_function.json index f7dda7d164..9849f288c4 100644 --- a/tests/translator/output/aws-cn/connector_api_to_function.json +++ b/tests/translator/output/aws-cn/connector_api_to_function.json @@ -15,7 +15,10 @@ "Type": "MOCK" }, "ResourceId": { - "Fn::GetAtt": ["MyApiGateway", "RootResourceId"] + "Fn::GetAtt": [ + "MyApiGateway", + "RootResourceId" + ] }, "RestApiId": { "Ref": "MyApiGateway" @@ -46,17 +49,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyServerlessFunction", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyApiGatewayV2" - }, - "SourceQualifier": "*" + } } ] } @@ -79,17 +85,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyServerlessFunction", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyApiGateway" - }, - "SourceQualifier": "*" + } } ] } @@ -112,17 +121,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyServerlessApi" - }, - "SourceQualifier": "*" + } } ] } @@ -145,17 +157,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyHttpApi" - }, - "SourceQualifier": "*" + } } ] } @@ -169,7 +184,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -243,7 +261,9 @@ "swagger": "2.0" }, "EndpointConfiguration": { - "Types": ["REGIONAL"] + "Types": [ + "REGIONAL" + ] }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" @@ -280,7 +300,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -297,10 +320,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-cn/connector_bucket_to_function.json b/tests/translator/output/aws-cn/connector_bucket_to_function.json index 8490c62fe8..e9e91ecbf9 100644 --- a/tests/translator/output/aws-cn/connector_bucket_to_function.json +++ b/tests/translator/output/aws-cn/connector_bucket_to_function.json @@ -1,7 +1,9 @@ { "Resources": { "Bucket": { - "DependsOn": ["MyConnectorWriteLambdaPermission"], + "DependsOn": [ + "MyConnectorWriteLambdaPermission" + ], "Properties": { "BucketName": "random-bucket-name", "NotificationConfiguration": { @@ -9,7 +11,10 @@ { "Event": "s3:ObjectCreated:*", "Function": { - "Fn::GetAtt": ["InvokedFunction", "Arn"] + "Fn::GetAtt": [ + "InvokedFunction", + "Arn" + ] } } ] @@ -24,7 +29,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["FunctionRole", "Arn"] + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -41,10 +49,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -78,7 +90,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["Function", "Arn"] + "Fn::GetAtt": [ + "Function", + "Arn" + ] }, "Principal": "s3.amazonaws.com", "SourceAccount": { diff --git a/tests/translator/output/aws-cn/connector_esm_dependson.json b/tests/translator/output/aws-cn/connector_esm_dependson.json index b63e9a587d..f5be6465e5 100644 --- a/tests/translator/output/aws-cn/connector_esm_dependson.json +++ b/tests/translator/output/aws-cn/connector_esm_dependson.json @@ -1,255 +1,313 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Role": { - "Ref": "SomeRole" - } - } - }, - "MyQueue1": { - "Type": "AWS::SQS::Queue" - }, - "MyQueue2": { - "Type": "AWS::SQS::Queue" - }, - "MyQueue3": { - "Type": "AWS::SQS::Queue" - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table" - }, - "MyEventSourceMapping1": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue1", "Arn"] - } - }, - "DependsOn": ["MyConnector1Policy"] - }, - "MyEventSourceMapping2": { - "DependsOn": ["SomeDep", "MyConnector2Policy"], - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue2", "Arn"] - } - } - }, - "MyEventSourceMapping3": { - "DependsOn": ["SomeOtherDep", "MyConnector3Policy"], - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue3", "Arn"] - } - } - }, - "MyEventSourceMapping4": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] - } - }, - "DependsOn": ["MyConnector4Policy"] - }, "MyConnector1Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector1": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector2Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector2": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector3Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector3": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue3", "Arn"] + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue3", "Arn"] + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector4Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector4": { - "Source": { - "Type": "AWS::DynamoDB::Table" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::DynamoDB::Table" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "dynamodb:DescribeStream", "dynamodb:GetRecords", "dynamodb:GetShardIterator", "dynamodb:ListStreams" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyEventSourceMapping1": { + "DependsOn": [ + "MyConnector1Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping2": { + "DependsOn": [ + "SomeDep", + "MyConnector2Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping3": { + "DependsOn": [ + "SomeOtherDep", + "MyConnector3Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping4": { + "DependsOn": [ + "MyConnector4Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunction": { + "Properties": { + "Role": { + "Ref": "SomeRole" + } + }, + "Type": "AWS::Lambda::Function" + }, + "MyQueue1": { + "Type": "AWS::SQS::Queue" + }, + "MyQueue2": { + "Type": "AWS::SQS::Queue" + }, + "MyQueue3": { + "Type": "AWS::SQS::Queue" + }, + "MyTable": { + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/aws-cn/connector_function_to_s3.json b/tests/translator/output/aws-cn/connector_function_to_s3.json index fd1b455c8e..482f14f296 100644 --- a/tests/translator/output/aws-cn/connector_function_to_s3.json +++ b/tests/translator/output/aws-cn/connector_function_to_s3.json @@ -38,14 +38,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/*", { "DestinationArn": { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] } } ] @@ -65,14 +71,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/*", { "DestinationArn": { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] } } ] @@ -97,7 +109,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -114,10 +129,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-cn/connector_function_to_sqs.json b/tests/translator/output/aws-cn/connector_function_to_sqs.json index d9a8e53e2c..925d831238 100644 --- a/tests/translator/output/aws-cn/connector_function_to_sqs.json +++ b/tests/translator/output/aws-cn/connector_function_to_sqs.json @@ -17,11 +17,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -62,7 +68,10 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -94,11 +103,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] }, @@ -112,7 +127,10 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -141,7 +159,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -176,7 +197,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -193,10 +217,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-cn/connector_function_to_table.json b/tests/translator/output/aws-cn/connector_function_to_table.json index 36a16d80cb..0dc8c1fd62 100644 --- a/tests/translator/output/aws-cn/connector_function_to_table.json +++ b/tests/translator/output/aws-cn/connector_function_to_table.json @@ -28,14 +28,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -81,14 +87,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -108,14 +120,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -161,14 +179,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -214,14 +238,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -253,7 +283,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -292,7 +325,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -309,10 +345,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-cn/connector_hardcoded_lambda_arn.json b/tests/translator/output/aws-cn/connector_hardcoded_lambda_arn.json index 1684af6d04..3da2074e63 100644 --- a/tests/translator/output/aws-cn/connector_hardcoded_lambda_arn.json +++ b/tests/translator/output/aws-cn/connector_hardcoded_lambda_arn.json @@ -19,7 +19,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["SomeLambda", "Arn"] + "Fn::GetAtt": [ + "SomeLambda", + "Arn" + ] }, "Principal": "sns.amazonaws.com", "SourceArn": { diff --git a/tests/translator/output/aws-cn/connector_hardcoded_props.json b/tests/translator/output/aws-cn/connector_hardcoded_props.json index 6571e85f5c..35916275e8 100644 --- a/tests/translator/output/aws-cn/connector_hardcoded_props.json +++ b/tests/translator/output/aws-cn/connector_hardcoded_props.json @@ -1,234 +1,201 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function" - }, - "MyRule": { - "Type": "AWS::Events::Rule" - }, - "MyQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyTopic": { - "Type": "AWS::SNS::Topic" - }, - "MyApiV1": { - "Type": "AWS::ApiGateway::RestApi" - }, - "MyApiV2": { - "Type": "AWS::ApiGatewayV2::Api" - }, - "MySfn": { - "Type": "AWS::StepFunctions::StateMachine" - }, - "RuleToTopicTopicPolicy": { - "Type": "AWS::SNS::TopicPolicy", + "ApiV1ToLambdaWriteLambdaPermission": { "Metadata": { "aws:sam:connectors": { - "RuleToTopic": { - "Source": { - "Type": "AWS::Events::Rule" - }, + "ApiV1ToLambda": { "Destination": { - "Type": "AWS::SNS::Topic" + "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::ApiGateway::RestApi" } } } }, "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { - "Effect": "Allow", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Resource": { - "Fn::GetAtt": ["Egg", "Baz"] - }, - "Action": "sns:Publish", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Fn::GetAtt": ["MyRule", "Arn"] - } - } + "SourceQualifier": "Prod/GET/foobar", + "SourceResourceId": { + "Ref": "MyApiV1" } } ] - }, - "Topics": [ - { - "Fn::GetAtt": ["Egg", "Baz"] - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, - "TopicToQueueQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "ApiV2ToLambdaWriteLambdaPermission": { "Metadata": { "aws:sam:connectors": { - "TopicToQueue": { - "Source": { - "Type": "AWS::SNS::Topic" - }, + "ApiV2ToLambda": { "Destination": { - "Type": "AWS::SQS::Queue" + "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::ApiGatewayV2::Api" } } } }, "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { - "Effect": "Allow", - "Principal": { - "Service": "sns.amazonaws.com" - }, - "Resource": { - "Ref": "MyQueue" - }, - "Action": "sqs:SendMessage", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "MyTopic" - } - } + "SourceQualifier": "*", + "SourceResourceId": { + "Ref": "MyApiV2" } } ] - }, - "Queues": [ - { - "Fn::If": [ - true, - { - "Ref": "Foo" - }, - { - "Ref": "Bar" - } - ] - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, "LambdaToQueuePolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "LambdaToQueue": { - "Source": { - "Type": "AWS::Lambda::Function" - }, "Destination": { "Type": "AWS::SQS::Queue" + }, + "Source": { + "Type": "AWS::Lambda::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "sqs:DeleteMessage", "sqs:SendMessage", "sqs:ChangeMessageVisibility", "sqs:PurgeQueue" ], + "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, - "Roles": ["MyCoolRole"] - } + "Roles": [ + "MyCoolRole" + ] + }, + "Type": "AWS::IAM::ManagedPolicy" }, - "ApiV1ToLambdaWriteLambdaPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiV1": { + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiV2": { + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyFunction": { + "Type": "AWS::Lambda::Function" + }, + "MyQueue": { + "Type": "AWS::SQS::Queue" + }, + "MyRule": { + "Type": "AWS::Events::Rule" + }, + "MySfn": { + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyTopic": { + "Type": "AWS::SNS::Topic" + }, + "RuleToTopicTopicPolicy": { "Metadata": { "aws:sam:connectors": { - "ApiV1ToLambda": { - "Source": { - "Type": "AWS::ApiGateway::RestApi" - }, + "RuleToTopic": { "Destination": { - "Type": "AWS::Lambda::Function" + "Type": "AWS::SNS::Topic" + }, + "Source": { + "Type": "AWS::Events::Rule" } } } }, "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", + "PolicyDocument": { + "Statement": [ { - "SourceResourceId": { - "Ref": "MyApiV1" + "Action": "sns:Publish", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Fn::GetAtt": [ + "MyRule", + "Arn" + ] + } + } }, - "SourceQualifier": "Prod/GET/foobar" - } - ] - } - } - }, - "ApiV2ToLambdaWriteLambdaPermission": { - "Type": "AWS::Lambda::Permission", - "Metadata": { - "aws:sam:connectors": { - "ApiV2ToLambda": { - "Source": { - "Type": "AWS::ApiGatewayV2::Api" - }, - "Destination": { - "Type": "AWS::Lambda::Function" + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "Egg", + "Baz" + ] + } } + ], + "Version": "2012-10-17" + }, + "Topics": [ + { + "Fn::GetAtt": [ + "Egg", + "Baz" + ] } - } + ] }, - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", - { - "SourceResourceId": { - "Ref": "MyApiV2" - }, - "SourceQualifier": "*" - } - ] - } - } + "Type": "AWS::SNS::TopicPolicy" }, "SfnToSfnPolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "SfnToSfn": { - "Source": { + "Destination": { "Type": "AWS::StepFunctions::StateMachine" }, - "Destination": { + "Source": { "Type": "AWS::StepFunctions::StateMachine" } } @@ -236,18 +203,22 @@ }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "states:DescribeExecution" + ], "Effect": "Allow", - "Action": ["states:DescribeExecution"], "Resource": [ { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", { "DestinationName": { - "Fn::GetAtt": ["MySfn", "Name"] + "Fn::GetAtt": [ + "MySfn", + "Name" + ] } } ] @@ -255,8 +226,10 @@ ] }, { + "Action": [ + "events:DescribeRule" + ], "Effect": "Allow", - "Action": ["events:DescribeRule"], "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" @@ -264,20 +237,29 @@ ] }, { + "Action": [ + "states:StartExecution" + ], "Effect": "Allow", - "Action": ["states:StartExecution"], - "Resource": ["some-other-arn"] + "Resource": [ + "some-other-arn" + ] }, { + "Action": [ + "states:StopExecution" + ], "Effect": "Allow", - "Action": ["states:StopExecution"], "Resource": [ { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", { "DestinationName": { - "Fn::GetAtt": ["MySfn", "Name"] + "Fn::GetAtt": [ + "MySfn", + "Name" + ] } } ] @@ -285,18 +267,77 @@ ] }, { + "Action": [ + "events:PutTargets", + "events:PutRule" + ], "Effect": "Allow", - "Action": ["events:PutTargets", "events:PutRule"], "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" } ] } - ] + ], + "Version": "2012-10-17" + }, + "Roles": [ + "MyRoleNice" + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "TopicToQueueQueuePolicy": { + "Metadata": { + "aws:sam:connectors": { + "TopicToQueue": { + "Destination": { + "Type": "AWS::SQS::Queue" + }, + "Source": { + "Type": "AWS::SNS::Topic" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "MyTopic" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "sns.amazonaws.com" + }, + "Resource": { + "Ref": "MyQueue" + } + } + ], + "Version": "2012-10-17" }, - "Roles": ["MyRoleNice"] - } + "Queues": [ + { + "Fn::If": [ + true, + { + "Ref": "Foo" + }, + { + "Ref": "Bar" + } + ] + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" } } } diff --git a/tests/translator/output/aws-cn/connector_hardcoded_rolename.json b/tests/translator/output/aws-cn/connector_hardcoded_rolename.json index 1c70d03b84..ffe25c1417 100644 --- a/tests/translator/output/aws-cn/connector_hardcoded_rolename.json +++ b/tests/translator/output/aws-cn/connector_hardcoded_rolename.json @@ -26,14 +26,19 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } ], "Version": "2012-10-17" }, - "Roles": ["MyCoolRole"] + "Roles": [ + "MyCoolRole" + ] }, "Type": "AWS::IAM::ManagedPolicy" }, @@ -44,7 +49,10 @@ }, "Handler": "foo", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "python3.9", "Tags": [ @@ -61,10 +69,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-cn/connector_rule_to_eventbus.json b/tests/translator/output/aws-cn/connector_rule_to_eventbus.json index e4c3f79d6b..462ea044dd 100644 --- a/tests/translator/output/aws-cn/connector_rule_to_eventbus.json +++ b/tests/translator/output/aws-cn/connector_rule_to_eventbus.json @@ -25,11 +25,16 @@ "PolicyDocument": { "Statement": [ { - "Action": ["events:PutEvents"], + "Action": [ + "events:PutEvents" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["EventBus", "Arn"] + "Fn::GetAtt": [ + "EventBus", + "Arn" + ] } ] } @@ -61,7 +66,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["events:PutEvents"], + "Action": [ + "events:PutEvents" + ], "Effect": "Allow", "Resource": [ { @@ -83,18 +90,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["EventBus", "Arn"] + "Fn::GetAtt": [ + "EventBus", + "Arn" + ] }, "Id": "EventBus", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] @@ -104,7 +119,9 @@ "MyNewEventsRuleToDefaultBus": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", @@ -115,7 +132,10 @@ }, "Id": "EventBus", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] diff --git a/tests/translator/output/aws-cn/connector_rule_to_sfn.json b/tests/translator/output/aws-cn/connector_rule_to_sfn.json index f5b90955d8..f5703dba97 100644 --- a/tests/translator/output/aws-cn/connector_rule_to_sfn.json +++ b/tests/translator/output/aws-cn/connector_rule_to_sfn.json @@ -17,7 +17,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["states:StartExecution"], + "Action": [ + "states:StartExecution" + ], "Effect": "Allow", "Resource": [ { @@ -39,18 +41,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["StateMachine", "Arn"] + "Fn::GetAtt": [ + "StateMachine", + "Arn" + ] }, "Id": "StateMachine", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] @@ -96,11 +106,17 @@ }, "DefinitionSubstitutions": { "definition_substitution_1": { - "Fn::GetAtt": ["StateMachineFunction", "Arn"] + "Fn::GetAtt": [ + "StateMachineFunction", + "Arn" + ] } }, "RoleArn": { - "Fn::GetAtt": ["StateMachineRole", "Arn"] + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] }, "StateMachineType": "EXPRESS", "Tags": [ @@ -117,10 +133,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["states.amazonaws.com"] + "Service": [ + "states.amazonaws.com" + ] } } ], @@ -132,7 +152,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ diff --git a/tests/translator/output/aws-cn/connector_rule_to_sns.json b/tests/translator/output/aws-cn/connector_rule_to_sns.json index 78fd335694..cffbb77f04 100644 --- a/tests/translator/output/aws-cn/connector_rule_to_sns.json +++ b/tests/translator/output/aws-cn/connector_rule_to_sns.json @@ -21,7 +21,10 @@ "Condition": { "ArnEquals": { "aws:SourceArn": { - "Fn::GetAtt": ["MyNewEventsRule", "Arn"] + "Fn::GetAtt": [ + "MyNewEventsRule", + "Arn" + ] } } }, @@ -47,18 +50,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["StateMachine", "Arn"] + "Fn::GetAtt": [ + "StateMachine", + "Arn" + ] }, "Id": "StateMachine", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] diff --git a/tests/translator/output/aws-cn/connector_samfunction_to_table.json b/tests/translator/output/aws-cn/connector_samfunction_to_table.json index cca1ed359f..75200def6f 100644 --- a/tests/translator/output/aws-cn/connector_samfunction_to_table.json +++ b/tests/translator/output/aws-cn/connector_samfunction_to_table.json @@ -1,34 +1,57 @@ { "Resources": { - "MyTable": { - "Type": "AWS::DynamoDB::Table", + "MyConnectorPolicy": { "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "AttributeDefinitions": [ - { - "AttributeName": "Id", - "AttributeType": "S" - } - ], - "KeySchema": [ + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", + "dynamodb:BatchGetItem", + "dynamodb:ConditionCheckItem", + "dynamodb:PartiQLSelect" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + }, + { + "Fn::Sub": [ + "${DestinationArn}/index/*", + { + "DestinationArn": { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + } + } + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ { - "AttributeName": "Id", - "KeyType": "HASH" + "Ref": "MyFunctionRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n const docClient = new AWS.DynamoDB.DocumentClient();\n await docClient.scan({ TableName: process.env.TABLE_NAME, }).promise();\n};\n" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] - }, - "Runtime": "nodejs14.x", "Environment": { "Variables": { "TABLE_NAME": { @@ -36,28 +59,40 @@ } } }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -68,48 +103,26 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", + "MyTable": { "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "dynamodb:GetItem", - "dynamodb:Query", - "dynamodb:Scan", - "dynamodb:BatchGetItem", - "dynamodb:ConditionCheckItem", - "dynamodb:PartiQLSelect" - ], - "Resource": [ - { - "Fn::GetAtt": ["MyTable", "Arn"] - }, - { - "Fn::Sub": [ - "${DestinationArn}/index/*", - { - "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] - } - } - ] - } - ] - } - ] - }, - "Roles": [ + "AttributeDefinitions": [ { - "Ref": "MyFunctionRole" + "AttributeName": "Id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "Id", + "KeyType": "HASH" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/aws-cn/connector_sfn_to_function.json b/tests/translator/output/aws-cn/connector_sfn_to_function.json index 1ff619d21d..59965c5ac1 100644 --- a/tests/translator/output/aws-cn/connector_sfn_to_function.json +++ b/tests/translator/output/aws-cn/connector_sfn_to_function.json @@ -17,11 +17,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeAsync", "lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeAsync", + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } ] } @@ -43,7 +49,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -60,10 +69,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -102,11 +115,17 @@ }, "DefinitionSubstitutions": { "definition_substitution_1": { - "Fn::GetAtt": ["StateMachineFunction", "Arn"] + "Fn::GetAtt": [ + "StateMachineFunction", + "Arn" + ] } }, "RoleArn": { - "Fn::GetAtt": ["MyStateMachineRole", "Arn"] + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] }, "StateMachineType": "EXPRESS", "Tags": [ @@ -123,10 +142,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["states.amazonaws.com"] + "Service": [ + "states.amazonaws.com" + ] } } ], @@ -138,7 +161,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ diff --git a/tests/translator/output/aws-cn/connector_sfn_to_sfn.json b/tests/translator/output/aws-cn/connector_sfn_to_sfn.json index b9fb53b4cf..d79e529b0d 100644 --- a/tests/translator/output/aws-cn/connector_sfn_to_sfn.json +++ b/tests/translator/output/aws-cn/connector_sfn_to_sfn.json @@ -1,22 +1,119 @@ { "Resources": { - "TriggerStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "MyConnectorPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Destination": { + "Type": "AWS::Serverless::StateMachine" + }, + "Source": { + "Type": "AWS::Serverless::StateMachine" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "states:DescribeExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": [ + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", + { + "DestinationName": { + "Fn::GetAtt": [ + "MyStateMachine", + "Name" + ] + } + } + ] + } + ] + }, + { + "Action": [ + "events:DescribeRule" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" + } + ] + }, + { + "Action": [ + "states:StartExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Ref": "MyStateMachine" + } + ] + }, + { + "Action": [ + "states:StopExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": [ + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", + { + "DestinationName": { + "Fn::GetAtt": [ + "MyStateMachine", + "Name" + ] + } + } + ] + } + ] + }, + { + "Action": [ + "events:PutTargets", + "events:PutRule" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "TriggerStateMachineRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyStateMachine": { "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", - " \"StartAt\": \"TryDoSomething\",", + " \"StartAt\": \"Success\",", " \"States\": {", - " \"TryDoSomething\": {", - " \"End\": true,", - " \"Parameters\": {", - " \"StateMachineArn\": \"${definition_substitution_1}\"", - " },", - " \"Resource\": \"arn:aws:states:::states:startExecution.sync:2\",", - " \"Type\": \"Task\"", + " \"Success\": {", + " \"Type\": \"Succeed\"", " }", " }", "}" @@ -25,32 +122,23 @@ }, "RoleArn": { "Fn::GetAtt": [ - "TriggerStateMachineRole", + "MyStateMachineRole", "Arn" ] }, - "StateMachineType": "STANDARD", + "StateMachineType": "EXPRESS", "Tags": [ { "Key": "stateMachine:createdBy", "Value": "SAM" } - ], - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Ref": "MyStateMachine" - } - } + ] }, - "DependsOn": [ - "MyConnectorPolicy" - ] + "Type": "AWS::StepFunctions::StateMachine" }, - "TriggerStateMachineRole": { - "Type": "AWS::IAM::Role", + "MyStateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -63,19 +151,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "TriggerStateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -86,7 +174,8 @@ } } ] - } + }, + "PolicyName": "MyStateMachineRolePolicy0" } ], "Tags": [ @@ -95,46 +184,58 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "TriggerStateMachine": { + "DependsOn": [ + "MyConnectorPolicy" + ], "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", - " \"StartAt\": \"Success\",", + " \"StartAt\": \"TryDoSomething\",", " \"States\": {", - " \"Success\": {", - " \"Type\": \"Succeed\"", + " \"TryDoSomething\": {", + " \"End\": true,", + " \"Parameters\": {", + " \"StateMachineArn\": \"${definition_substitution_1}\"", + " },", + " \"Resource\": \"arn:aws:states:::states:startExecution.sync:2\",", + " \"Type\": \"Task\"", " }", " }", "}" ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Ref": "MyStateMachine" + } + }, "RoleArn": { "Fn::GetAtt": [ - "MyStateMachineRole", + "TriggerStateMachineRole", "Arn" ] }, - "StateMachineType": "EXPRESS", + "StateMachineType": "STANDARD", "Tags": [ { "Key": "stateMachine:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", + "TriggerStateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -147,19 +248,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "MyStateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -170,7 +271,8 @@ } } ] - } + }, + "PolicyName": "TriggerStateMachineRolePolicy0" } ], "Tags": [ @@ -179,110 +281,8 @@ "Value": "SAM" } ] - } - }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", - "Metadata": { - "aws:sam:connectors": { - "MyConnector": { - "Source": { - "Type": "AWS::Serverless::StateMachine" - }, - "Destination": { - "Type": "AWS::Serverless::StateMachine" - } - } - } }, - "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "states:DescribeExecution" - ], - "Resource": [ - { - "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", - { - "DestinationName": { - "Fn::GetAtt": [ - "MyStateMachine", - "Name" - ] - } - } - ] - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "events:DescribeRule" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "states:StartExecution" - ], - "Resource": [ - { - "Ref": "MyStateMachine" - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "states:StopExecution" - ], - "Resource": [ - { - "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", - { - "DestinationName": { - "Fn::GetAtt": [ - "MyStateMachine", - "Name" - ] - } - } - ] - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "events:PutTargets", - "events:PutRule" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" - } - ] - } - ] - }, - "Roles": [ - { - "Ref": "TriggerStateMachineRole" - } - ] - } + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/connector_sns_to_function.json b/tests/translator/output/aws-cn/connector_sns_to_function.json index e5054c69c2..d353e61557 100644 --- a/tests/translator/output/aws-cn/connector_sns_to_function.json +++ b/tests/translator/output/aws-cn/connector_sns_to_function.json @@ -16,7 +16,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "sns.amazonaws.com", "SourceArn": { @@ -39,7 +42,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, diff --git a/tests/translator/output/aws-cn/connector_sns_to_sqs.json b/tests/translator/output/aws-cn/connector_sns_to_sqs.json index 9b6063a4b9..556f77cd4e 100644 --- a/tests/translator/output/aws-cn/connector_sns_to_sqs.json +++ b/tests/translator/output/aws-cn/connector_sns_to_sqs.json @@ -33,7 +33,10 @@ "Service": "sns.amazonaws.com" }, "Resource": { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } } ], @@ -80,7 +83,10 @@ "Service": "sns.amazonaws.com" }, "Resource": { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } } ], @@ -99,13 +105,19 @@ "Subscription": [ { "Endpoint": { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] }, "Protocol": "sqs" }, { "Endpoint": { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] }, "Protocol": "sqs" } diff --git a/tests/translator/output/aws-cn/connector_sqs_to_function.json b/tests/translator/output/aws-cn/connector_sqs_to_function.json index 5be32a9794..42ec15cc11 100644 --- a/tests/translator/output/aws-cn/connector_sqs_to_function.json +++ b/tests/translator/output/aws-cn/connector_sqs_to_function.json @@ -17,20 +17,31 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:DeleteMessage"], + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] } ] }, { - "Action": ["sqs:GetQueueAttributes", "sqs:ReceiveMessage"], + "Action": [ + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] } ] } @@ -59,7 +70,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["InvokedFunctionRole", "Arn"] + "Fn::GetAtt": [ + "InvokedFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -76,10 +90,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -93,14 +111,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -124,11 +147,16 @@ "Type": "AWS::SQS::Queue" }, "SQSEventSourceMapping": { - "DependsOn": ["ConnectorPolicy"], + "DependsOn": [ + "ConnectorPolicy" + ], "Properties": { "BatchSize": 10, "EventSourceArn": { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] }, "FunctionName": { "Ref": "InvokedFunction" @@ -153,7 +181,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["TriggerFunctionRole", "Arn"] + "Fn::GetAtt": [ + "TriggerFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -171,10 +202,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -202,7 +237,10 @@ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -216,14 +254,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["Queue", "QueueName"] + "Fn::GetAtt": [ + "Queue", + "QueueName" + ] } } ] diff --git a/tests/translator/output/aws-cn/connector_table_to_function.json b/tests/translator/output/aws-cn/connector_table_to_function.json index e038dcb2b1..ed90208e1d 100644 --- a/tests/translator/output/aws-cn/connector_table_to_function.json +++ b/tests/translator/output/aws-cn/connector_table_to_function.json @@ -30,7 +30,10 @@ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -62,7 +65,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, diff --git a/tests/translator/output/aws-cn/connector_table_to_function_read.json b/tests/translator/output/aws-cn/connector_table_to_function_read.json index f7d74e0909..90f02cbcdc 100644 --- a/tests/translator/output/aws-cn/connector_table_to_function_read.json +++ b/tests/translator/output/aws-cn/connector_table_to_function_read.json @@ -29,14 +29,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] } } ] @@ -84,7 +90,10 @@ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] } } ] @@ -103,15 +112,23 @@ "Type": "AWS::IAM::ManagedPolicy" }, "DynamoDBTableStream": { - "DependsOn": ["ConnectorPolicy"], + "DependsOn": [ + "ConnectorPolicy" + ], "Properties": { "BatchSize": 1, "Enabled": true, "EventSourceArn": { - "Fn::GetAtt": ["Table", "StreamArn"] + "Fn::GetAtt": [ + "Table", + "StreamArn" + ] }, "FunctionName": { - "Fn::GetAtt": ["InvokedFunction", "Arn"] + "Fn::GetAtt": [ + "InvokedFunction", + "Arn" + ] }, "StartingPosition": "TRIM_HORIZON" }, @@ -131,7 +148,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["InvokedFunctionRole", "Arn"] + "Fn::GetAtt": [ + "InvokedFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -148,10 +168,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -165,14 +189,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -230,7 +259,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["TriggerFunctionRole", "Arn"] + "Fn::GetAtt": [ + "TriggerFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -248,10 +280,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -279,7 +315,10 @@ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] diff --git a/tests/translator/output/aws-cn/definition_body_intrinsics_support.json b/tests/translator/output/aws-cn/definition_body_intrinsics_support.json index e8693dc49e..31d11e6717 100644 --- a/tests/translator/output/aws-cn/definition_body_intrinsics_support.json +++ b/tests/translator/output/aws-cn/definition_body_intrinsics_support.json @@ -1,154 +1,154 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", - "Conditions": { - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", + "Resources": { + "HttpApiIfIntrinsicAndNoOpenApiEditor": { + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + } + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/" + } + } + } + } + } + ] } + }, + "Type": "AWS::ApiGatewayV2::Api" }, - "Resources": { - "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", - "RestApiId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" - }, - "StageName": "Stage" - } - }, - "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" - }, - "RestApiId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" - }, - "StageName": "prod" - } + "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { + "Properties": { + "ApiId": { + "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" }, - "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" - }, - "StageName": "prod", - "AutoDeploy": true - } - }, - "RestApiIfIntrinsicAndNoSwaggerEditor": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "Fn::If": [ - "FalseCondition", - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "swagger": "2.0" - }, - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otheruri.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "swagger": "2.0" - } - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + "AutoDeploy": true, + "StageName": "prod" + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "RestApiIfIntrinsicAndNoSwaggerEditor": { + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" } - } - }, - "HttpApiIfIntrinsicAndNoOpenApiEditor": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "Fn::If": [ - "FalseCondition", - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "openapi": "3.0" - }, - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otheruri.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "openapi": "3.0" - } - ] + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + }, + "swagger": "2.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/" + } + } + } + }, + "swagger": "2.0" } + ] + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { + "Properties": { + "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" + }, + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "prod" + }, + "Type": "AWS::ApiGateway::Stage" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/depends_on.json b/tests/translator/output/aws-cn/depends_on.json index f051149853..a5b96cd8a5 100644 --- a/tests/translator/output/aws-cn/depends_on.json +++ b/tests/translator/output/aws-cn/depends_on.json @@ -1,7 +1,50 @@ { "Resources": { + "MyExplicitApi": { + "DependsOn": "MySamTable", + "Properties": { + "BodyS3Location": { + "Bucket": "sam-translator-tests-dont-delete", + "Key": "swagger-http.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyExplicitApiDeployment74b681ce04": { + "Properties": { + "Description": "RestApi deployment id: 74b681ce04601a2cf69b6d05d53782b216cf96bb", + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyExplicitApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyExplicitApiDeployment74b681ce04" + }, + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", + "DependsOn": [ + "MyExplicitApi", + "MySamTable" + ], "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,147 +60,104 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyExplicitApi", - "MySamTable" - ] + "Type": "AWS::Lambda::Function" }, - "MyExplicitApiDeployment74b681ce04": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionMyApiPermissiondev": { "Properties": { - "RestApiId": { - "Ref": "MyExplicitApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Description": "RestApi deployment id: 74b681ce04601a2cf69b6d05d53782b216cf96bb", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "MyExplicitApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionRole": { "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-translator-tests-dont-delete", - "Key": "swagger-http.json" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "DependsOn": "MySamTable" + "Type": "AWS::IAM::Role" }, "MyOtherTable": { - "Type": "AWS::DynamoDB::Table", + "DependsOn": "MySamTable", "Properties": { - "KeySchema": [ + "AttributeDefinitions": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "AttributeType": "S" } ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "KeySchema": [ { "AttributeName": "id", - "AttributeType": "S" + "KeyType": "HASH" } ], "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" } }, - "DependsOn": "MySamTable" - }, - "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyExplicitApiDeployment74b681ce04" - }, - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "StageName": "dev" - } + "Type": "AWS::DynamoDB::Table" }, "MySamTable": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "MyExplicitApi" - } - ] - } - } + }, + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/aws-cn/error_function_with_invalid_stream_eventsource_dest_type.json b/tests/translator/output/aws-cn/error_function_with_invalid_stream_eventsource_dest_type.json index dc4f300bdf..f52c232d90 100644 --- a/tests/translator/output/aws-cn/error_function_with_invalid_stream_eventsource_dest_type.json +++ b/tests/translator/output/aws-cn/error_function_with_invalid_stream_eventsource_dest_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/aws-cn/error_function_with_missing_on_failure_in_stream_event_destination_config.json b/tests/translator/output/aws-cn/error_function_with_missing_on_failure_in_stream_event_destination_config.json index dcc5d33fb1..a60f6883d3 100644 --- a/tests/translator/output/aws-cn/error_function_with_missing_on_failure_in_stream_event_destination_config.json +++ b/tests/translator/output/aws-cn/error_function_with_missing_on_failure_in_stream_event_destination_config.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/aws-cn/eventbridgerule.json b/tests/translator/output/aws-cn/eventbridgerule.json index 91c6a68e8f..0919448878 100644 --- a/tests/translator/output/aws-cn/eventbridgerule.json +++ b/tests/translator/output/aws-cn/eventbridgerule.json @@ -1,185 +1,185 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/eventbridgerule_schedule_properties.json b/tests/translator/output/aws-cn/eventbridgerule_schedule_properties.json index 4f463b8345..2f2cc99111 100644 --- a/tests/translator/output/aws-cn/eventbridgerule_schedule_properties.json +++ b/tests/translator/output/aws-cn/eventbridgerule_schedule_properties.json @@ -1,93 +1,120 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -95,93 +122,66 @@ "terminated" ] } - }, + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Name": "test-schedule", - "Description": "Test Schedule", - "State": "ENABLED", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json index 42a20c35ab..813b02553e 100644 --- a/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json +++ b/tests/translator/output/aws-cn/eventbridgerule_with_dlq.json @@ -1,240 +1,240 @@ { "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ScheduledFunctionScheduleQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Queues": [ + "ScheduleExpression": "rate(1 minute)", + "State": "ENABLED", + "Targets": [ { - "Ref": "ScheduledFunctionScheduleQueue" + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "DeadLetterConfig": { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunctionScheduleQueue", + "Arn" + ] + } + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" } - ], + ] + }, + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionScheduleQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "ScheduledFunctionScheduleQueuePolicy": { + "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "ScheduledFunctionScheduleQueue", - "Arn" - ] - }, - "Effect": "Allow", + "Action": "sqs:SendMessage", "Condition": { "ArnEquals": { "aws:SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } } - }, + }, + "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "ScheduledFunctionScheduleQueue", + "Arn" + ] } } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "ScheduledFunctionScheduleQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "TriggeredFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TriggeredFunctionRole", + "Arn" ] - } - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", - "State" : "ENABLED", + }, + "State": "ENABLED", "Targets": [ { - "DeadLetterConfig": { - "Arn": "ARN" - }, - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "DeadLetterConfig": { + "Arn": "ARN" + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "TriggeredFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", + "TriggeredFunctionOnTerminate", "Arn" ] } - } - }, - "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule", - "Arn" - ] - } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { - "Fn::GetAtt": [ - "ScheduledFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionScheduleQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { - "Fn::GetAtt": [ - "TriggeredFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "State" : "ENABLED", - "Targets": [ - { - "DeadLetterConfig": { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunctionScheduleQueue", - "Arn" - ] - } - }, - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/eventbridgerule_with_retry_policy.json b/tests/translator/output/aws-cn/eventbridgerule_with_retry_policy.json index d1ab9d8487..9b8c5924e2 100644 --- a/tests/translator/output/aws-cn/eventbridgerule_with_retry_policy.json +++ b/tests/translator/output/aws-cn/eventbridgerule_with_retry_policy.json @@ -1,189 +1,189 @@ { "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - }, + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 200, + "MaximumEventAgeInSeconds": 200, "MaximumRetryAttempts": 3 } } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/explicit_api.json b/tests/translator/output/aws-cn/explicit_api.json index 81fb57d359..63eefda8aa 100644 --- a/tests/translator/output/aws-cn/explicit_api.json +++ b/tests/translator/output/aws-cn/explicit_api.json @@ -1,179 +1,178 @@ { "Parameters": { - "something": { - "Default": "something", - "Type": "String" - }, "MyStageName": { - "Default": "Production", + "Default": "Production", + "Type": "String" + }, + "something": { + "Default": "something", "Type": "String" } - }, + }, "Resources": { - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "ApiWithInlineSwagger": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "webpage.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Body": { + "a": "inline swagger", + "this": "is" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiWithInlineSwaggerDeployment09cda3d97b": { + "Properties": { + "Description": "RestApi deployment id: 09cda3d97b008bed7bd4ebb1b5304ed622492941", + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiWithInlineSwaggerStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithInlineSwaggerDeployment09cda3d97b" - }, + }, "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, + }, "StageName": { "Ref": "MyStageName" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "MyGetApi", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", "RestApiId": { "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + }, "StageName": "Stage" - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "EndpointUri": { + "Ref": "something" + }, + "EndpointUri2": "http://example.com" } - } - }, - "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "Body": { - "this": "is", - "a": "inline swagger" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "webpage.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "GetHtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "GetHtmlApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": "MyGetApi" - } - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "EndpointUri": { - "Ref": "something" - }, - "EndpointUri2": "http://example.com" - }, - "StageName": { - "Ref": "MyStageName" - } - } - }, - "ApiWithInlineSwaggerDeployment09cda3d97b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 09cda3d97b008bed7bd4ebb1b5304ed622492941", - "StageName": "Stage" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/explicit_api_openapi_3.json b/tests/translator/output/aws-cn/explicit_api_openapi_3.json index 38e863d3ad..36f676857e 100644 --- a/tests/translator/output/aws-cn/explicit_api_openapi_3.json +++ b/tests/translator/output/aws-cn/explicit_api_openapi_3.json @@ -1,178 +1,177 @@ { "Parameters": { - "something": { - "Default": "something", - "Type": "String" - }, "MyStageName": { - "Default": "Production", + "Default": "Production", + "Type": "String" + }, + "something": { + "Default": "something", "Type": "String" } - }, + }, "Resources": { - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "ApiWithInlineSwagger": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "webpage.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Body": { + "a": "inline swagger", + "this": "is" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiWithInlineSwaggerDeployment74abcb3a5b": { + "Properties": { + "Description": "RestApi deployment id: 74abcb3a5bbe7ad58dfc543740af3be156736130", + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiWithInlineSwaggerStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithInlineSwaggerDeployment74abcb3a5b" - }, + }, "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, + }, "StageName": { "Ref": "MyStageName" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "MyGetApi", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", "RestApiId": { "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + }, "StageName": "Stage" - } - }, - "ApiWithInlineSwaggerDeployment74abcb3a5b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 74abcb3a5bbe7ad58dfc543740af3be156736130" - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "EndpointUri": { + "Ref": "something" + }, + "EndpointUri2": "http://example.com" + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "webpage.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "inline swagger" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "GetHtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "GetHtmlApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": "MyGetApi" - } - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "EndpointUri": { - "Ref": "something" - }, - "EndpointUri2": "http://example.com" - }, - "StageName": { - "Ref": "MyStageName" - } - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/explicit_api_with_invalid_events_config.json b/tests/translator/output/aws-cn/explicit_api_with_invalid_events_config.json index c4238ab30e..6d3eb70b4b 100644 --- a/tests/translator/output/aws-cn/explicit_api_with_invalid_events_config.json +++ b/tests/translator/output/aws-cn/explicit_api_with_invalid_events_config.json @@ -1,134 +1,134 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionAddApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", - { - "__Stage__": "*", - "__ApiId__": "ApiWithInlineSwagger" - } - ] - } - } - }, - "ApiWithInlineSwaggerProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiWithInlineSwaggerDeployment22d399868d" - }, - "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "StageName": "Prod" - } - }, "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/foo": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ApiWithInlineSwaggerDeployment22d399868d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 22d399868d5755a0d5204deae1ee870cf95a7737", "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 22d399868d5755a0d5204deae1ee870cf95a7737", + }, "StageName": "Stage" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiWithInlineSwaggerProdStage": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "DeploymentId": { + "Ref": "ApiWithInlineSwaggerDeployment22d399868d" + }, + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAddApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + { + "__ApiId__": "ApiWithInlineSwagger", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/explicit_http_api.json b/tests/translator/output/aws-cn/explicit_http_api.json index 2eebb7bb86..31d0cee889 100644 --- a/tests/translator/output/aws-cn/explicit_http_api.json +++ b/tests/translator/output/aws-cn/explicit_http_api.json @@ -1,258 +1,258 @@ { "Resources": { - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunctionBasePathPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Apiv2" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "ANY", - "type": "http_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "isDefaultRoute": true, - "security": [ - { - "OAuth2": [] - } - ] - } - }, - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "OAuth2": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "OAuth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Ref": "MyApi2" + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionBasePathPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApi2" - } + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { - "FailOnWarnings": true, "Body": { + "components": { + "securitySchemes": { + "OAuth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, + "isDefaultRoute": true, + "responses": {}, "security": [ { "OAuth2": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } } - }, - "openapi": "3.0.1", + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + }, + "FailOnWarnings": true + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2": { + "Properties": { + "Body": { "components": { "securitySchemes": { "OAuth2": { - "type": "oauth2", + "type": "oauth2", "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", + "identitySource": "$request.querystring.param", "jwtConfiguration": { "audience": [ "MyApi" - ], + ], "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Apiv2" + } + }, + "openapi": "3.0", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "security": [ + { + "OAuth2": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "payloadFormatVersion": "1.0", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/" + } + } + }, + "/": { + "get": { + "responses": {}, + "security": [ + { + "OAuth2": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } } } } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/explicit_http_api_minimum.json b/tests/translator/output/aws-cn/explicit_http_api_minimum.json index 09367ab43e..256133cbcf 100644 --- a/tests/translator/output/aws-cn/explicit_http_api_minimum.json +++ b/tests/translator/output/aws-cn/explicit_http_api_minimum.json @@ -1,161 +1,161 @@ { "Resources": { + "Api": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "Api" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "Api": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], - "paths": {}, - "openapi": "3.0.1" - } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, - "openapi": "3.0.1" + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] } - } - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "Api" - }, - "AutoDeploy": true, - "StageName": "$default", + }, + "AutoDeploy": true, + "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-cn/function_concurrency.json b/tests/translator/output/aws-cn/function_concurrency.json index c7cdb002b9..2bffc6ab7b 100644 --- a/tests/translator/output/aws-cn/function_concurrency.json +++ b/tests/translator/output/aws-cn/function_concurrency.json @@ -5,20 +5,35 @@ } }, "Resources": { - "ConcurrentFunctionRole": { - "Type": "AWS::IAM::Role", + "AnotherFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": { + "Ref": "Concurrency" + }, + "Role": { + "Fn::GetAtt": [ + "AnotherFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "AnotherFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -30,18 +45,30 @@ "lambda.amazonaws.com" ] } - }] - } - } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ConcurrentFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "ConcurrentFunctionRole", @@ -49,27 +76,18 @@ ] }, "Runtime": "python2.7", - "ReservedConcurrentExecutions": 100, - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "AnotherFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ConcurrentFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -81,33 +99,21 @@ "lambda.amazonaws.com" ] } - }] - } - } - }, - "AnotherFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + } + ], + "Version": "2012-10-17" }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "AnotherFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "ReservedConcurrentExecutions": { - "Ref": "Concurrency" - }, - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_event_conditions.json b/tests/translator/output/aws-cn/function_event_conditions.json index 1e1ee3b383..5702ab45db 100644 --- a/tests/translator/output/aws-cn/function_event_conditions.json +++ b/tests/translator/output/aws-cn/function_event_conditions.json @@ -8,371 +8,473 @@ } }, "Resources": { - "MyAwesomeFunctionAliasLive": { - "Type": "AWS::Lambda::Alias", - "Condition": "MyCondition", + "FunctionOne": { "Properties": { - "FunctionVersion": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { "Fn::GetAtt": [ - "MyAwesomeFunctionVersion640128d35d", - "Version" + "FunctionOneRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "MyAwesomeFunction" - }, - "Name": "Live" - } - }, - "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionOneImageBucketPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Ref": "Notifications" + "Ref": "FunctionOne" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionCWEventPermission": { - "Type": "AWS::Lambda::Permission", + "FunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "FunctionOneImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Fn::If": [ + "MyCondition", + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Ref": "MyAwesomeFunctionAliasLive" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionOne", + "Arn" + ] + } + } + ] + }, + "Tags": [ + { + "Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission", + "Value": { + "Fn::If": [ + "MyCondition", + { + "Ref": "MyAwesomeFunctionS3TriggerPermission" + }, + "no dependency" + ] + } + } + ] + }, + "Type": "AWS::S3::Bucket" + }, + "MyAwesomeFunction": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "MyAwesomeFunctionCWEvent", + "MyAwesomeFunctionRole", "Arn" ] - } - } + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyAwesomeFunctionEBRulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionAliasLive": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" + "Ref": "MyAwesomeFunction" }, - "SourceArn": { + "FunctionVersion": { "Fn::GetAtt": [ - "MyAwesomeFunctionEBRule", + "MyAwesomeFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "Live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyAwesomeFunctionAnotherSNSWithSQSSubscription": { + "Condition": "MyCondition", + "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", "Arn" ] + }, + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" }, - "MyAwesomeFunctionDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionEventSourceMapping": { "Condition": "MyCondition", "Properties": { - "BatchSize": 200, - "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", + "Arn" + ] + }, "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "LATEST" - } + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionIoTRule": { - "Type": "AWS::IoT::TopicRule", + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue": { + "Condition": "MyCondition", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueuePolicy": { "Condition": "MyCondition", "Properties": { - "TopicRulePayload": { - "AwsIotSqlVersion": "beta", - "Actions": [ + "PolicyDocument": { + "Statement": [ { - "Lambda": { - "FunctionArn": { - "Ref": "MyAwesomeFunctionAliasLive" + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", + "Arn" + ] } } - ], - "RuleDisabled": false, - "Sql": "SELECT * FROM 'topic/test'" - } - } - }, - "MyAwesomeFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "MyAwesomeFunctionCWEvent": { "Condition": "MyCondition", "Properties": { - "BatchSize": 100, - "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "TRIM_HORIZON" - } + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionCWEventLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" }, - "MyAwesomeFunctionIoTRulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionCWEventPermission": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", - { - "RuleName": { - "Ref": "MyAwesomeFunctionIoTRule" - } - } + "Fn::GetAtt": [ + "MyAwesomeFunctionCWEvent", + "Arn" ] } - } - }, - "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", - "Condition": "MyCondition", - "Properties": { - "Endpoint": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Protocol": "lambda", - "TopicArn": { - "Ref": "Notifications" - } - } - }, - "MyAwesomeFunctionS3TriggerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionCWLog": { "Condition": "MyCondition", + "DependsOn": [ + "MyAwesomeFunctionCWLogPermission" + ], "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { + "DestinationArn": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "Principal": "s3.amazonaws.com" - } + }, + "FilterPattern": "My pattern", + "LogGroupName": "MyLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "MyAwesomeFunctionCWLogPermission": { - "Type": "AWS::Lambda::Permission", "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", + "arn:aws-cn:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", { "__LogGroupName__": "MyLogGroup" } ] } - } - }, - "MyAwesomeFunctionEBSchedule": { - "Type": "AWS::Events::Rule", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionDDBStream": { "Condition": "MyCondition", "Properties": { - "ScheduleExpression": "rate(1 minute)", + "BatchSize": 200, + "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionEBRule": { + "Condition": "MyCondition", + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "launched" + ] + } + }, "Targets": [ { - "Id": "MyAwesomeFunctionEBScheduleLambdaTarget", "Arn": { "Ref": "MyAwesomeFunctionAliasLive" - } + }, + "Id": "MyAwesomeFunctionEBRuleLambdaTarget" } ] - } - }, - "MyAwesomeFunctionCWLog": { - "Type": "AWS::Logs::SubscriptionFilter", + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBRulePermission": { "Condition": "MyCondition", "Properties": { - "DestinationArn": { + "Action": "lambda:InvokeFunction", + "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "FilterPattern": "My pattern", - "LogGroupName": "MyLogGroup" - }, - "DependsOn": [ - "MyAwesomeFunctionCWLogPermission" - ] - }, - "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionEBRule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionEBSchedule": { "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ + "ScheduleExpression": "rate(1 minute)", + "Targets": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBScheduleLambdaTarget" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBSchedulePermission": { "Condition": "MyCondition", "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "MyAwesomeFunctionRole", + "MyAwesomeFunctionEBSchedule", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyAwesomeFunctionCWEvent": { - "Type": "AWS::Events::Rule", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionIoTRule": { "Condition": "MyCondition", "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "Id": "MyAwesomeFunctionCWEventLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" + "TopicRulePayload": { + "Actions": [ + { + "Lambda": { + "FunctionArn": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } } - } - ] - } + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, + "Sql": "SELECT * FROM 'topic/test'" + } + }, + "Type": "AWS::IoT::TopicRule" }, - "MyAwesomeFunctionEBRule": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionIoTRulePermission": { "Condition": "MyCondition", "Properties": { - "EventPattern": { - "detail": { - "state": [ - "launched" - ] - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Targets": [ - { - "Id": "MyAwesomeFunctionEBRuleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + { + "RuleName": { + "Ref": "MyAwesomeFunctionIoTRule" + } } - } - ] - } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "MyAwesomeFunctionKinesisStream": { "Condition": "MyCondition", "Properties": { + "BatchSize": 100, + "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", "FunctionName": { - "Ref": "MyAwesomeFunction" - } - } - }, - "Notifications": { - "Condition": "MyCondition", - "Type": "AWS::SNS::Topic" - }, - "MyAwesomeFunctionEBSchedulePermission": { - "Type": "AWS::Lambda::Permission", + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionNotificationTopic": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { + "Endpoint": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionEBSchedule", - "Arn" - ] + }, + "Protocol": "lambda", + "TopicArn": { + "Ref": "Notifications" } - } - }, - "FunctionOneImageBucketPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::SNS::Subscription" + }, + "MyAwesomeFunctionNotificationTopicPermission": { + "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, "FunctionName": { - "Ref": "FunctionOne" + "Ref": "MyAwesomeFunctionAliasLive" }, - "Principal": "s3.amazonaws.com" - } + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" }, - "FunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyAwesomeFunctionRole": { + "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -385,84 +487,40 @@ ] } } - ] - } - } - }, - "FunctionOne": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "FunctionOneRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "Images": { - "Type": "AWS::S3::Bucket", + "MyAwesomeFunctionS3TriggerPermission": { + "Condition": "MyCondition", "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Fn::If": [ - "MyCondition", - { - "Function": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Event": "s3:ObjectCreated:*" - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - { - "Function": { - "Fn::GetAtt": [ - "FunctionOne", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Tags": [ - { - "Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission", - "Value": { - "Fn::If": [ - "MyCondition", - { - "Ref": "MyAwesomeFunctionS3TriggerPermission" - }, - "no dependency" - ] - } - } - ] - }, - "DependsOn": [ - "FunctionOneImageBucketPermission" - ] + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionSNSTopicWithSQSSubscription": { - "Type": "AWS::SNS::Subscription", + "Condition": "MyCondition", "Properties": { "Endpoint": { "Fn::GetAtt": [ @@ -475,117 +533,32 @@ "Ref": "Notifications" } }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionSNSTopicWithSQSSubscriptionQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", - "Properties": { - "Queues": [ - { - "Ref": "Queue" - } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - }, - "Condition": "MyCondition" + "Type": "AWS::SNS::Subscription" }, "MyAwesomeFunctionSNSTopicWithSQSSubscriptionEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", + "Condition": "MyCondition", "Properties": { "BatchSize": 10, "Enabled": true, - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, "EventSourceArn": { "Fn::GetAtt": [ "Queue", "Arn" ] - } - }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue": { - "Condition": "MyCondition", - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, + }, "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - } - }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscription": { - "Type": "AWS::SNS::Subscription", - "Properties": { - "Endpoint": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" } }, - "Condition": "MyCondition" + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "MyAwesomeFunctionSNSTopicWithSQSSubscriptionQueuePolicy": { + "Condition": "MyCondition", "Properties": { - "Queues": [ - { - "Ref": "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - }, - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -593,16 +566,43 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + } } - ] + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "Queue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "MyAwesomeFunctionVersion640128d35d": { + "Condition": "MyCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MyAwesomeFunction" } }, - "Condition": "MyCondition" + "Type": "AWS::Lambda::Version" + }, + "Notifications": { + "Condition": "MyCondition", + "Type": "AWS::SNS::Topic" }, "Queue": { - "Type": "AWS::SQS::Queue", - "Condition": "MyCondition" + "Condition": "MyCondition", + "Type": "AWS::SQS::Queue" } } } diff --git a/tests/translator/output/aws-cn/function_managed_inline_policy.json b/tests/translator/output/aws-cn/function_managed_inline_policy.json index af76c76210..c03a6003d9 100644 --- a/tests/translator/output/aws-cn/function_managed_inline_policy.json +++ b/tests/translator/output/aws-cn/function_managed_inline_policy.json @@ -1,85 +1,85 @@ { "Parameters": { "SomeManagedPolicyArn": { - "Default": "arn:aws:iam::aws:policy/OtherPolicy", + "Default": "arn:aws:iam::aws:policy/OtherPolicy", "Type": "String" } - }, + }, "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", { "Ref": "SomeManagedPolicyArn" - }, + }, "arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "FunctionRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionRolePolicy0" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_alias.json b/tests/translator/output/aws-cn/function_with_alias.json index cf8953e96f..c487d02884 100644 --- a/tests/translator/output/aws-cn/function_with_alias.json +++ b/tests/translator/output/aws-cn/function_with_alias.json @@ -1,82 +1,82 @@ { "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_alias_and_code_sha256.json b/tests/translator/output/aws-cn/function_with_alias_and_code_sha256.json index b92a1b908d..2b434fa9f2 100644 --- a/tests/translator/output/aws-cn/function_with_alias_and_code_sha256.json +++ b/tests/translator/output/aws-cn/function_with_alias_and_code_sha256.json @@ -1,89 +1,89 @@ { - "Parameters": { - "AutoPublishCodeSha256": { - "Type": "String", - "Description": "Sha256 to uniquely identify creation of the lambda", - "Default": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" - } - }, - "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Parameters": { + "AutoPublishCodeSha256": { + "Default": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b", + "Description": "Sha256 to uniquely identify creation of the lambda", + "Type": "String" + } + }, + "Resources": { + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] - } - }, - "MinimalFunctionVersion6b86b273ff": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion6b86b273ff", - "Version" - ] - } - } + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion6b86b273ff", + "Version" + ] + }, + "Name": "live" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion6b86b273ff": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json b/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json index e48747d796..b61186ff13 100644 --- a/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json +++ b/tests/translator/output/aws-cn/function_with_alias_and_event_sources.json @@ -1,169 +1,332 @@ { "Parameters": { "MyStageName": { - "Default": "beta", + "Default": "beta", "Type": "String" } - }, + }, "Resources": { + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "MyGetApi", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "GetHtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "LambdaFunction": { + "Ref": "MyAwesomeFunction" + } + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Images": { + "DependsOn": [ + "MyAwesomeFunctionS3TriggerPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } + ] + } + }, + "Type": "AWS::S3::Bucket" + }, + "MyAwesomeFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyAwesomeFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyAwesomeFunctionAliasLive": { - "Type": "AWS::Lambda::Alias", "Properties": { + "FunctionName": { + "Ref": "MyAwesomeFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MyAwesomeFunctionVersion640128d35d", + "MyAwesomeFunctionVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "MyAwesomeFunction" - }, + }, "Name": "Live" - } - }, - "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Alias" + }, + "MyAwesomeFunctionCWEvent": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionCWEventLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionCWEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { - "Ref": "Notifications" + "Fn::GetAtt": [ + "MyAwesomeFunctionCWEvent", + "Arn" + ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment042edc7e2e" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionCWLog": { + "DependsOn": [ + "MyAwesomeFunctionCWLogPermission" + ], "Properties": { - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "MyAwesomeFunctionCWEventPermission": { - "Type": "AWS::Lambda::Permission", + "DestinationArn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "FilterPattern": "My pattern", + "LogGroupName": "MyLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" + }, + "MyAwesomeFunctionCWLogPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "logs.amazonaws.com", "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionCWEvent", - "Arn" + "Fn::Sub": [ + "arn:aws-cn:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", + { + "__LogGroupName__": "MyLogGroup" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionDDBStream": { + "Properties": { + "BatchSize": 200, + "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionEBRule": { + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "launched" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBRuleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" }, "MyAwesomeFunctionEBRulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ "MyAwesomeFunctionEBRule", "Arn" ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionEBSchedule": { + "Properties": { + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBSchedulePermission": { "Properties": { - "BatchSize": 200, - "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "LATEST" - } + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionEBSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionIoTRule": { - "Type": "AWS::IoT::TopicRule", + "MyAwesomeFunctionExplicitApiPermissionStage": { "Properties": { - "TopicRulePayload": { - "AwsIotSqlVersion": "beta", - "Actions": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Lambda": { - "FunctionArn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } + "__ApiId__": { + "Ref": "GetHtmlApi" + }, + "__Stage__": "*" } - ], - "RuleDisabled": false, - "Sql": "SELECT * FROM 'topic/test'" + ] } - } - }, - "MyAwesomeFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 100, - "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "TRIM_HORIZON" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyAwesomeFunctionImplicitApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionIoTRule": { + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "Lambda": { + "FunctionArn": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } + } + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, + "Sql": "SELECT * FROM 'topic/test'" + } + }, + "Type": "AWS::IoT::TopicRule" + }, "MyAwesomeFunctionIoTRulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", { "RuleName": { "Ref": "MyAwesomeFunctionIoTRule" @@ -171,322 +334,159 @@ } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionKinesisStream": { + "Properties": { + "BatchSize": 100, + "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } - }, - "MyAwesomeFunctionS3TriggerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Principal": "s3.amazonaws.com" - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": "MyGetApi" - } + }, + "Type": "AWS::SNS::Subscription" }, - "MyAwesomeFunctionCWLogPermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionNotificationTopicPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "sns.amazonaws.com", "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", - { - "__LogGroupName__": "MyLogGroup" - } - ] + "Ref": "Notifications" } - } - }, - "MyAwesomeFunctionEBSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "MyAwesomeFunctionEBScheduleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } - }, - "MyAwesomeFunctionCWLog": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "FilterPattern": "My pattern", - "LogGroupName": "MyLogGroup" - }, - "DependsOn": [ - "MyAwesomeFunctionCWLogPermission" - ] - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyAwesomeFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyAwesomeFunctionCWEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "Id": "MyAwesomeFunctionCWEventLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyAwesomeFunctionEBRule": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionS3TriggerPermission": { "Properties": { - "EventPattern": { - "detail": { - "state": [ - "launched" - ] - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Targets": [ - { - "Id": "MyAwesomeFunctionEBRuleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MyAwesomeFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "Notifications": { + "Type": "AWS::SNS::Topic" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyAwesomeFunctionAliasLive}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "Notifications": { - "Type": "AWS::SNS::Topic" - }, - "MyAwesomeFunctionEBSchedulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionEBSchedule", - "Arn" - ] - } - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Event": "s3:ObjectCreated:*" - } - ] - } - }, - "DependsOn": [ - "MyAwesomeFunctionS3TriggerPermission" - ] - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "LambdaFunction": { - "Ref": "MyAwesomeFunction" - } - }, - "StageName": { - "Ref": "MyStageName" - } - } - }, - "MyAwesomeFunctionExplicitApiPermissionStage": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "GetHtmlApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ServerlessRestApiDeployment042edc7e2e": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 042edc7e2e15e52c1da7abc216d273b4d7761e9a", "RestApiId": { "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 042edc7e2e15e52c1da7abc216d273b4d7761e9a", + }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment042edc7e2e" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/function_with_alias_intrinsics.json b/tests/translator/output/aws-cn/function_with_alias_intrinsics.json index 3fff52854b..12174d6f4c 100644 --- a/tests/translator/output/aws-cn/function_with_alias_intrinsics.json +++ b/tests/translator/output/aws-cn/function_with_alias_intrinsics.json @@ -1,87 +1,87 @@ { "Parameters": { "AliasName": { - "Default": "live", + "Default": "live", "Type": "String" } - }, + }, "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_amq.json b/tests/translator/output/aws-cn/function_with_amq.json index 6a34ed7714..9cc14a23ea 100644 --- a/tests/translator/output/aws-cn/function_with_amq.json +++ b/tests/translator/output/aws-cn/function_with_amq.json @@ -1,7 +1,6 @@ { "Resources": { "MQFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,30 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MQFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,14 +56,14 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", "PolicyDocument": { "Statement": [ { @@ -65,7 +81,8 @@ "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" } ] - } + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" } ], "Tags": [ @@ -74,25 +91,8 @@ "Value": "SAM" } ] - } - }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_amq_kms.json b/tests/translator/output/aws-cn/function_with_amq_kms.json index e79122065e..6d36ba8809 100644 --- a/tests/translator/output/aws-cn/function_with_amq_kms.json +++ b/tests/translator/output/aws-cn/function_with_amq_kms.json @@ -1,105 +1,105 @@ { - "Resources": { - "MQFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "queues.zip" - }, - "Handler": "queue.mq_handler", - "Role": { - "Fn::GetAtt": [ - "MQFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Resources": { + "MQFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "queues.zip" + }, + "Handler": "queue.mq_handler", + "Role": { + "Fn::GetAtt": [ + "MQFunctionRole", + "Arn" ] - } + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MQFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MQFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "mq:DescribeBroker" - ], - "Effect": "Allow", - "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" - } - } + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "mq:DescribeBroker" + ], + "Effect": "Allow", + "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" + }, + { + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" + } + } + ] + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" + } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ] - } - } + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/function_with_architectures.json b/tests/translator/output/aws-cn/function_with_architectures.json index 7e9b898cf7..35066a6928 100644 --- a/tests/translator/output/aws-cn/function_with_architectures.json +++ b/tests/translator/output/aws-cn/function_with_architectures.json @@ -3,8 +3,10 @@ "Parameters": {}, "Resources": { "TestFunc": { - "Type": "AWS::Lambda::Function", "Properties": { + "Architectures": [ + "arm64" + ], "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" @@ -19,23 +21,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ], - "Architectures": [ - "arm64" - ] - } + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "TestFuncRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -48,7 +46,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -59,7 +58,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_auth_mechanism_for_self_managed_kafka.json b/tests/translator/output/aws-cn/function_with_auth_mechanism_for_self_managed_kafka.json index b446ea8782..99ed327ca3 100644 --- a/tests/translator/output/aws-cn/function_with_auth_mechanism_for_self_managed_kafka.json +++ b/tests/translator/output/aws-cn/function_with_auth_mechanism_for_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +65,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -70,32 +94,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_condition.json b/tests/translator/output/aws-cn/function_with_condition.json index 4fbd2abf82..2643dcece2 100644 --- a/tests/translator/output/aws-cn/function_with_condition.json +++ b/tests/translator/output/aws-cn/function_with_condition.json @@ -2,66 +2,66 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "test", + "test", "test" ] } - }, + }, "Resources": { "ConditionFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "TestCondition", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ConditionFunctionRole", + "ConditionFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "TestCondition" - }, + }, + "Type": "AWS::Lambda::Function" + }, "ConditionFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "TestCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "TestCondition" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_conditional_managed_policy.json b/tests/translator/output/aws-cn/function_with_conditional_managed_policy.json index a71779ff91..a89243623e 100644 --- a/tests/translator/output/aws-cn/function_with_conditional_managed_policy.json +++ b/tests/translator/output/aws-cn/function_with_conditional_managed_policy.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,12 +22,34 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", { @@ -54,24 +69,9 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_conditional_managed_policy_and_ref_no_value.json b/tests/translator/output/aws-cn/function_with_conditional_managed_policy_and_ref_no_value.json index 794ee731d8..18867d273c 100644 --- a/tests/translator/output/aws-cn/function_with_conditional_managed_policy_and_ref_no_value.json +++ b/tests/translator/output/aws-cn/function_with_conditional_managed_policy_and_ref_no_value.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,12 +22,34 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", { @@ -54,24 +69,9 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_conditional_policy_template.json b/tests/translator/output/aws-cn/function_with_conditional_policy_template.json index 9dc9f720a6..2b0a316c60 100644 --- a/tests/translator/output/aws-cn/function_with_conditional_policy_template.json +++ b/tests/translator/output/aws-cn/function_with_conditional_policy_template.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,33 +22,49 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithConditionalPolicyRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { "Fn::If": [ "DummyCondition", { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${secretArn}", @@ -63,14 +72,13 @@ "secretArn": "Dummy Secret Arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" }, { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { @@ -80,10 +88,6 @@ "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" ], - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" - }, - "Effect": "Allow", "Condition": { "StringEquals": { "secretsmanager:resource/AllowRotationLambdaArn": { @@ -95,38 +99,34 @@ ] } } + }, + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" } }, { "Action": [ "secretsmanager:GetRandomPassword" ], - "Resource": "*", - "Effect": "Allow" + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" } ] } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_conditional_policy_template_and_ref_no_value.json b/tests/translator/output/aws-cn/function_with_conditional_policy_template_and_ref_no_value.json index 109cf48195..b14869c03c 100644 --- a/tests/translator/output/aws-cn/function_with_conditional_policy_template_and_ref_no_value.json +++ b/tests/translator/output/aws-cn/function_with_conditional_policy_template_and_ref_no_value.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,33 +22,49 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithConditionalPolicyRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { "Fn::If": [ "DummyCondition", { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${secretArn}", @@ -63,11 +72,11 @@ "secretArn": "Dummy Secret Arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" }, { "Ref": "AWS::NoValue" @@ -75,23 +84,14 @@ ] } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json index f3d5e0510f..4aa9a67b86 100644 --- a/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json +++ b/tests/translator/output/aws-cn/function_with_custom_codedeploy_deployment_preference.json @@ -1,906 +1,906 @@ { - "Parameters": { - "Deployment": { - "Default": "AllAtOnce", - "Type": "String" - }, - "Custom": { - "Default": "CustomDeployment", - "Type": "String" - }, - "Stage": { - "Default": "beta", - "Type": "String" - } - }, "Conditions": { "MyCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Mappings": { "DeploymentPreferenceMap": { "beta": { "DeploymentPreference": "CustomDeployment" - }, + }, "prod": { "DeploymentPreference": "AllAtOnce" } } - }, + }, + "Parameters": { + "Custom": { + "Default": "CustomDeployment", + "Type": "String" + }, + "Deployment": { + "Default": "AllAtOnce", + "Type": "String" + }, + "Stage": { + "Default": "beta", + "Type": "String" + } + }, "Resources": { - "NormalWithRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "NormalWithRefDeploymentGroup" + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithCondition": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "CustomWithConditionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithCondition2": { "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "CustomWithCondition2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithCondition2Aliaslive": { + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" + }, "FunctionVersion": { "Fn::GetAtt": [ - "NormalWithRefVersion640128d35d", + "CustomWithCondition2Version640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "NormalWithRef" - }, + }, "Name": "live" - } - }, - "CustomWithFindInMapVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithFindInMap" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithCondition2DeploymentGroup" + } } } - }, + }, "CustomWithCondition2DeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "CustomDeployment" ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "CustomWithFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithFindInMapDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "CustomWithFindInMapVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "CustomWithFindInMap" - }, - "Name": "live" - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "CodeDeployServiceRole", "Arn" ] - }, - "Runtime": "python2.7", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithCondition2Role": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithSubAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithSubDeploymentGroup" - } + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithCondition2Version640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithConditionAliaslive": { "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + }, "FunctionVersion": { "Fn::GetAtt": [ - "CustomWithSubVersion640128d35d", + "CustomWithConditionVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "CustomWithSub" - }, + }, "Name": "live" - } - }, - "NormalWithSub": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "NormalWithSubRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithConditionDeploymentGroup" } - ] - } - }, - "CustomWithConditionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithCondition" } } - }, - "CustomWithSubDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithConditionDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + "TestDeploymentConfiguration", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": "CustomDeployment" - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "CustomWithCondition2Version640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithCondition2" - } - } - }, - "CustomWithCondition": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithConditionRole": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "CustomWithConditionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithSub": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithConditionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + } + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithFindInMap": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "CustomWithSubRole", + "CustomWithFindInMapRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "NormalWithRefVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithFindInMapAliaslive": { "Properties": { "FunctionName": { - "Ref": "NormalWithRef" + "Ref": "CustomWithFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithFindInMapVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithFindInMapDeploymentGroup" + } } } - }, - "NormalWithSubDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithFindInMapDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": "CustomDeployment", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithFindInMapRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithFindInMapVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithFindInMap" } - } - }, - "NormalWithRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithSub": { "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CustomWithSubRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "NormalWithSubAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "NormalWithSubDeploymentGroup" + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithSubAliaslive": { "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" + }, "FunctionVersion": { "Fn::GetAtt": [ - "NormalWithSubVersion640128d35d", + "CustomWithSubVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "NormalWithSub" - }, + }, "Name": "live" - } - }, - "CustomWithSubVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithSub" - } - } - }, - "CustomWithSubRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "CustomWithConditionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithSubDeploymentGroup" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] } } - }, - "CustomWithConditionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithSubDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": "CustomDeployment" + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::If": [ - "MyCondition", - "TestDeploymentConfiguration", - { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithSubRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" } - } - }, - "CustomWithFindInMap": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunction": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "CustomWithFindInMapRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "NormalWithSubVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { "Properties": { "FunctionName": { - "Ref": "NormalWithSub" - } - } - }, - "CustomWithConditionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { - "Ref": "CustomWithConditionDeploymentGroup" + "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "CustomWithConditionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "CustomWithCondition" - }, - "Name": "live" - } - }, - "CustomWithFindInMapRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "NormalWithRef": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "NormalWithRefRole", + "NormalWithRefRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithCondition2": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "NormalWithRefAliaslive": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { + "FunctionName": { + "Ref": "NormalWithRef" + }, + "FunctionVersion": { "Fn::GetAtt": [ - "CustomWithCondition2Role", - "Arn" + "NormalWithRefVersion640128d35d", + "Version" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithRefDeploymentGroup" } - ] + } } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "NormalWithRefDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": "TestDeploymentConfiguration", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, "NormalWithRefRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "CustomWithCondition2Aliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithCondition2DeploymentGroup" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "NormalWithRefVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "NormalWithRef" } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "NormalWithSub": { "Properties": { - "FunctionVersion": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CustomWithCondition2Version640128d35d", - "Version" + "NormalWithSubRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "CustomWithCondition2" - }, - "Name": "live" - } - }, - "NormalWithSubRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "NormalWithSubAliaslive": { "Properties": { "FunctionName": { - "Ref": "MinimalFunction" + "Ref": "NormalWithSub" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithSubVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithSubDeploymentGroup" + } } } - }, - "CustomWithFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "NormalWithSubDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": "CustomDeployment", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, - "CustomWithCondition2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "NormalWithSubRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "NormalWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "NormalWithSub" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json b/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json index 26c5417e6b..c356925f84 100644 --- a/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json +++ b/tests/translator/output/aws-cn/function_with_custom_conditional_codedeploy_deployment_preference.json @@ -1,199 +1,199 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": { - "EnvType": { - "Default": "dev", - "Type": "String" - } - }, + "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "IsDevEnv2": { + "IsDevEnv": { "Fn::Equals": [ { "Ref": "EnvType" - }, - "prod" + }, + "dev" ] - }, - "IsDevEnv": { + }, + "IsDevEnv2": { "Fn::Equals": [ { "Ref": "EnvType" - }, - "dev" + }, + "prod" ] } - }, + }, + "Parameters": { + "EnvType": { + "Default": "dev", + "Type": "String" + } + }, "Resources": { - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "HelloWorldFunction": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "HelloWorldFunctionVersionfb53d5c2e6", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "HelloWorldFunctionDeploymentGroup" + } } } - }, + }, "HelloWorldFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::If": [ - "IsDevEnv", + "IsDevEnv", { "Fn::If": [ - "IsDevEnv2", + "IsDevEnv2", { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "TestCustomDeploymentConfig" ] - }, + }, { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Canary10Percent15Minutes" } ] } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "HelloWorldFunctionVersionfb53d5c2e6": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "HelloWorldFunction" - } - } - }, - "HelloWorldFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "HelloWorldFunctionDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "HelloWorldFunctionVersionfb53d5c2e6", - "Version" - ] - }, - "FunctionName": { - "Ref": "HelloWorldFunction" - }, - "Name": "live" - } - }, - "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "HelloWorldFunctionRole", + "CodeDeployServiceRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "HelloWorldFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "HelloWorldFunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json b/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json index 03a936a6df..6f14b401ce 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json +++ b/tests/translator/output/aws-cn/function_with_deployment_and_custom_role.json @@ -1,270 +1,270 @@ { "Resources": { - "FunctionWithRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "DeploymentRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "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", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithRole": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "DeploymentRole", + "Arn" ] - } - } - }, - "FunctionWithRoleVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithRoleAliaslive": { "Properties": { "FunctionName": { "Ref": "FunctionWithRole" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FunctionWithRoleVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FunctionWithRoleDeploymentGroup" + } } } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "FunctionWithRoleDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FunctionWithRoleVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FunctionWithRole" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "FunctionWithRoleDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "MinimalFunctionDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } - }, - "FunctionWithRoleAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FunctionWithRoleDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionWithRoleVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "FunctionWithRole" - }, - "Name": "live" - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json index 801fd6cb3f..db7c0663d6 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json +++ b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_with_passthrough.json @@ -8,66 +8,9 @@ } }, "Resources": { - "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "Condition1" - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "DeploymentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -76,90 +19,68 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" ] - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "DeploymentRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { "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" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -172,9 +93,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -184,34 +102,62 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "MinimalFunctionRole": { "Properties": { - "ComputePlatform": "Lambda" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunctionVersion640128d35d": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "OtherFunctionRole", @@ -221,39 +167,27 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + "OtherFunctionAliaslive": { + "Condition": "Condition1", "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] }, - "FunctionName": { - "Ref": "MinimalFunction" - }, "Name": "live" - } - }, - "OtherFunctionAliaslive": { + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -264,20 +198,86 @@ "Ref": "OtherFunctionDeploymentGroup" } } - }, + } + }, + "OtherFunctionDeploymentGroup": { "Condition": "Condition1", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", - "Version" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } ] }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "OtherFunctionRole": { + "Condition": "Condition1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "OtherFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "OtherFunction" - }, - "Name": "live" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json index 704201e999..79c461a604 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json +++ b/tests/translator/output/aws-cn/function_with_deployment_no_service_role_without_passthrough.json @@ -8,65 +8,9 @@ } }, "Resources": { - "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "DeploymentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -75,90 +19,68 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" ] - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "DeploymentRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { "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" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -171,9 +93,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -183,34 +102,62 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "MinimalFunctionRole": { "Properties": { - "ComputePlatform": "Lambda" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunctionVersion640128d35d": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "OtherFunctionRole", @@ -220,39 +167,27 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + "OtherFunctionAliaslive": { + "Condition": "Condition1", "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] }, - "FunctionName": { - "Ref": "MinimalFunction" - }, "Name": "live" - } - }, - "OtherFunctionAliaslive": { + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -263,20 +198,85 @@ "Ref": "OtherFunctionDeploymentGroup" } } + } + }, + "OtherFunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + } }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "OtherFunctionRole": { "Condition": "Condition1", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", - "Version" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "OtherFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "OtherFunction" - }, - "Name": "live" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference.json b/tests/translator/output/aws-cn/function_with_deployment_preference.json index 830ecaa182..3188d2b29c 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference.json @@ -4,192 +4,192 @@ "Fn::Equals": [ { "Ref": "EnableAliasProvisionedConcurrency" - }, + }, true ] } - }, + }, "Parameters": { "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, + ], + "Default": true, + "Type": "String" + }, "FnName": { "Type": "String" - }, + }, "ProvisionedConcurrency": { - "Default": 10, + "Default": 10, "Type": "String" } - }, + }, "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" } + }, + { + "Ref": "AWS::NoValue" } ] } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "Name": "live", - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - }, - { - "Ref": "AWS::NoValue" } - ] + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_alarms_intrinsic_if.json b/tests/translator/output/aws-cn/function_with_deployment_preference_alarms_intrinsic_if.json index 077d23fc8e..0ac77fded1 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_alarms_intrinsic_if.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_alarms_intrinsic_if.json @@ -8,8 +8,31 @@ } }, "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -29,18 +52,22 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "MinimalFunctionAliaslive": { "Properties": { "FunctionName": { "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -51,88 +78,14 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "AlarmConfiguration": { "Fn::If": [ "MyCondition", { - "Enabled": true, "Alarms": [ { "Name": "Alarm1" @@ -143,10 +96,10 @@ { "Name": "Alarm3" } - ] + ], + "Enabled": true }, { - "Enabled": true, "Alarms": [ { "Name": "Alarm1" @@ -154,7 +107,8 @@ { "Name": "Alarm5" } - ] + ], + "Enabled": true } ] }, @@ -178,8 +132,8 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, "ServiceRoleArn": { "Fn::GetAtt": [ @@ -187,7 +141,53 @@ "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_all_parameters.json b/tests/translator/output/aws-cn/function_with_deployment_preference_all_parameters.json index 739a818115..1d242b7f05 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_all_parameters.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_all_parameters.json @@ -1,138 +1,121 @@ { "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery1Minute" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] }, @@ -142,162 +125,179 @@ "DeploymentSuccess", "DeploymentFailure" ], + "TriggerName": "TestTrigger", "TriggerTargetArn": { "Ref": "MySNSTopic" - }, - "TriggerName": "TestTrigger" + } } ] - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", + "MySanityTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MySNSTopic": { - "Type": "AWS::SNS::Topic" + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json index 1e82b66128..bdf0df3211 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_with_passthrough.json @@ -17,12 +17,12 @@ }, "Parameters": { "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", "AllowedValues": [ true, false - ] + ], + "Default": true, + "Type": "String" }, "FnName": { "Type": "String" @@ -33,46 +33,10 @@ } }, "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { + "Condition": "FunctionCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -81,32 +45,27 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "Condition": "FunctionCondition" + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -116,56 +75,40 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition" + "Type": "AWS::Lambda::Function" }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { + "Condition": "FunctionCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" } + }, + { + "Ref": "AWS::NoValue" } ] } }, - "Condition": "FunctionCondition" - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionAliaslive": { "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -176,33 +119,90 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Condition": "FunctionCondition", "Properties": { - "Name": "live", - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Ref": "AWS::NoValue" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Condition": "FunctionCondition", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json index 5660e1f9f0..cc80d8e687 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_condition_without_passthrough.json @@ -1,205 +1,205 @@ { - "Conditions": { - "AliasProvisionedConcurrencyEnabled": { - "Fn::Equals": [ - { - "Ref": "EnableAliasProvisionedConcurrency" - }, - true + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "AllowedValues": [ + true, + false + ], + "Default": true, + "Type": "String" + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "FunctionCondition": { - "Fn::Equals": [ - true, - true - ] - } + "Type": "AWS::IAM::Role" }, - "Parameters": { - "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", - "AllowedValues": [ - true, - false + "MinimalFunction": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] }, - "FnName": { - "Type": "String" - }, - "ProvisionedConcurrency": { - "Default": 10, - "Type": "String" - } + "Type": "AWS::Lambda::Function" }, - "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { + "MinimalFunctionAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" } } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + } + }, + "MinimalFunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "Condition": "FunctionCondition" - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Value": "SAM", - "Key": "lambda:createdBy" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, - "Condition": "FunctionCondition" + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "FunctionCondition" + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, - "Condition": "FunctionCondition", - "Properties": { - "Name": "live", - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - } - } - } + "Type": "AWS::CodeDeploy::Application" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json b/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json index 0e83fb6c66..6d1db44e28 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_from_parameters.json @@ -1,152 +1,135 @@ { "Parameters": { - "MyTrueParameter": { - "Default": "True", - "Type": "String" - }, "MyLowerFalseParameter": { "Default": "false", "Type": "String" }, + "MyTrueParameter": { + "Default": "True", + "Type": "String" + }, "MyUpperFalseParameter": { "Default": "False", "Type": "String" } }, "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery1Minute" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] }, @@ -156,162 +139,179 @@ "DeploymentSuccess", "DeploymentFailure" ], + "TriggerName": "TestTrigger", "TriggerTargetArn": { "Ref": "MySNSTopic" - }, - "TriggerName": "TestTrigger" + } } ] - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", + "MySanityTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MySNSTopic": { - "Type": "AWS::SNS::Topic" + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json index 7c9543aa57..08b343cf6c 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations.json @@ -1,486 +1,486 @@ { "Resources": { - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" ] - } - } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { - "Type": "AWS::Lambda::Alias", + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" } } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - }, - "Name": "livewithdeployment" } - }, + }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery2Minutes" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "MinimalFunctionWithMinimalDeploymentPreferenceRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { "Properties": { - "Code": { - "S3Bucket": "my-bucket", - "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", - "Role": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", - "Arn" + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Name": "livewithdeployment" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" } - ] - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" } } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, + }, "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Canary10Percent5Minutes" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } - } - }, - "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySanityTestFunction": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - }, - "Name": "livewithdeploymentwithhooksandalarms" - } - }, + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyValidationTestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json index 2999c3fd16..be492ef184 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json @@ -1,19 +1,9 @@ { "Conditions": { - "ServerlessCodeDeployCondition": { - "Fn::Or": [ - { - "Condition": "Condition2" - }, - { - "Condition": "Condition1" - } - ] - }, - "Condition3": { + "Condition1": { "Fn::Equals": [ true, - false + true ] }, "Condition2": { @@ -22,10 +12,20 @@ false ] }, - "Condition1": { + "Condition3": { "Fn::Equals": [ true, - true + false + ] + }, + "ServerlessCodeDeployCondition": { + "Fn::Or": [ + { + "Condition": "Condition2" + }, + { + "Condition": "Condition1" + } ] } }, @@ -36,38 +36,39 @@ } }, "Resources": { - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "CodeDeployServiceRole": { + "Condition": "ServerlessCodeDeployCondition", "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "Condition": "Condition2" + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -77,50 +78,41 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionAliaslive": { + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "FunctionName": { + "Ref": "MinimalFunction" }, - "Role": { + "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", - "Arn" + "MinimalFunctionVersion640128d35d", + "Version" ] }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] + "Name": "live" }, - "Condition": "Condition2" + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "Condition1", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -133,12 +125,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -148,30 +134,22 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "Condition1" - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionRole": { + "Condition": "Condition1", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,54 +158,79 @@ "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } }, - "Condition": "ServerlessCodeDeployCondition" + "Type": "AWS::Lambda::Version" }, - "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Condition": "Condition2", "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "ServiceRoleArn": { + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Canary10Percent5Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "Condition2" + "Type": "AWS::Lambda::Function" }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Condition": "Condition2", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, @@ -236,92 +239,59 @@ }, "DeploymentGroupName": { "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" } } - }, - "Condition": "Condition2", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - }, - "Name": "livewithdeploymentwithhooksandalarms" } }, - "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "Condition": "Condition2", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "AlarmConfiguration": { + "Alarms": [ { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Name": { + "Ref": "MyCloudWatchAlarm" } } + ], + "Enabled": true + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "ConfigName": "Linear10PercentEvery2Minutes" } ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -334,53 +304,83 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition3" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Condition": "Condition2", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeployment" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "Condition": "Condition2", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -397,23 +397,13 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery2Minutes" + "ConfigName": "Canary10Percent5Minutes" } ] }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, "ServiceRoleArn": { "Fn::GetAtt": [ @@ -422,23 +412,12 @@ ] } }, - "Condition": "Condition2" - }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -451,54 +430,50 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition2" + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" - } - } - }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { "Condition": "Condition2", + "DeletionPolicy": "Retain", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" - ] - }, "FunctionName": { "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - }, - "Name": "livewithdeployment" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition3", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MySanityTestFunctionRole", @@ -508,64 +483,51 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition3" - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - }, - "Condition": "ServerlessCodeDeployCondition" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "MySanityTestFunctionRole": { + "Condition": "Condition3", "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "Condition1" - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "Condition": "Condition1", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + "Type": "AWS::IAM::Role" }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyValidationTestFunctionRole", @@ -575,11 +537,49 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyValidationTestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessDeploymentApplication": { + "Condition": "ServerlessCodeDeployCondition", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json index 6e2b173249..04e9df0985 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json @@ -21,24 +21,36 @@ }, "Parameters": { "MyFalseParameter": { - "Type": "String", - "Default": false + "Default": false, + "Type": "String" } }, "Resources": { - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", + "CodeDeployServiceRole": { "Properties": { - "ComparisonOperator": "GreaterThanThreshold", - "EvaluationPeriods": 1, - "MetricName": "MyMetric", - "Namespace": "AWS/EC2", - "Period": 300, - "Threshold": 10 - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Condition": "Condition1", "Properties": { "Code": { @@ -59,21 +71,24 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionAliaslive": { "Condition": "Condition1", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition1", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { @@ -83,26 +98,46 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionVersion": { + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "Condition1", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -115,7 +150,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -126,10 +162,20 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { "Condition": "Condition2", "Properties": { "Code": { @@ -139,7 +185,7 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] }, @@ -150,50 +196,89 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { "Condition": "Condition2", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition2", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" } } - }, + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { "Properties": { - "Name": "livewithdeployment", - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true }, - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -206,7 +291,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -217,10 +303,20 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithMinimalDeploymentPreference": { "Condition": "Condition2", "Properties": { "Code": { @@ -230,7 +326,7 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "MinimalFunctionWithMinimalDeploymentPreferenceRole", "Arn" ] }, @@ -241,56 +337,73 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { "Condition": "Condition2", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - } - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeployment" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition2", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" } } - }, + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { "Properties": { - "Name": "livewithdeploymentwithhooksandalarms", - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionVersion": { + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -303,7 +416,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -314,10 +428,31 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Condition": "Condition3", "Properties": { "Code": { @@ -338,14 +473,13 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "Condition3", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -358,7 +492,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -369,10 +504,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "my-bucket", @@ -392,13 +527,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -411,7 +545,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -422,149 +557,14 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", "Properties": { "ComputePlatform": "Lambda" - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] - } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery2Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Canary10Percent5Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "AlarmConfiguration": { - "Enabled": true, - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ] - }, - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery2Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json b/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json index 7e26228d82..255544bf68 100644 --- a/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json +++ b/tests/translator/output/aws-cn/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json @@ -1,649 +1,649 @@ { - "Mappings": { - "HelloWorldMap": { - "hello": { - "key1": true, - "key2": false - }, - "world": { - "key1": false, - "key2": true - } - } + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] }, - "Parameters": { - "FnName": { - "Type": "String" - }, - "ProvisionedConcurrency": { - "Type": "String", - "Default": 10 - }, - "EnableAliasProvisionedConcurrency": { - "Type": "String", - "AllowedValues": [ - true, - false - ], - "Default": true - }, - "DefaultTrueParam": { - "Type": "String", - "Default": "true" - }, - "DefaultFalseParam": { - "Type": "String", - "Default": "false" - }, - "HelloParam": { - "Type": "String", - "Default": "hello" - }, - "WorldParam": { - "Type": "String", - "Default": "world" - } + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Mappings": { + "HelloWorldMap": { + "hello": { + "key1": true, + "key2": false + }, + "world": { + "key1": false, + "key2": true + } + } + }, + "Parameters": { + "DefaultFalseParam": { + "Default": "false", + "Type": "String" }, - "Conditions": { - "AliasProvisionedConcurrencyEnabled": { - "Fn::Equals": [ - { - "Ref": "EnableAliasProvisionedConcurrency" - }, - true - ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - true - ] - } + "DefaultTrueParam": { + "Default": "true", + "Type": "String" + }, + "EnableAliasProvisionedConcurrency": { + "AllowedValues": [ + true, + false + ], + "Default": true, + "Type": "String" + }, + "FnName": { + "Type": "String" + }, + "HelloParam": { + "Default": "hello", + "Type": "String" }, - "Resources": { - "TrueRef": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "TrueRefRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + }, + "WorldParam": { + "Default": "world", + "Type": "String" + } + }, + "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "TrueRefVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "TrueRef" - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseFindInMap": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseFindInMapRole", + "Arn" + ] }, - "TrueRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "TrueRefDeploymentGroup" - } - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FalseFindInMapAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseFindInMapVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "TrueRef" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "TrueRefVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseFindInMapDeploymentGroup" + } + } + } + }, + "FalseFindInMapDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueRefRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "FalseRef": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FalseRefRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FalseFindInMapRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "FalseRefVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "FalseRef" - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseFindInMapVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + } + }, + "Type": "AWS::Lambda::Version" + }, + "FalseRef": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "FalseRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FalseRefDeploymentGroup" - } - } + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FalseRefAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseRefVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "FalseRef" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FalseRefVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseRefDeploymentGroup" + } + } + } + }, + "FalseRefDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FalseRefRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, - "TrueFindInMap": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "TrueFindInMapRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FalseRefRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "TrueFindInMapVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "TrueFindInMap" - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseRefVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" + }, + "TrueFindInMap": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "TrueFindInMapAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueFindInMapVersion640128d35d", + "Version" + ] }, - "TrueFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "TrueFindInMapDeploymentGroup" - } - } + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "TrueFindInMap" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "TrueFindInMapVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueFindInMapDeploymentGroup" + } + } + } + }, + "TrueFindInMapDeploymentGroup": { + "Condition": "FunctionCondition", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueFindInMapRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "FalseFindInMap": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FalseFindInMapRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "TrueFindInMapRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "FalseFindInMapVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "FalseFindInMap" - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TrueFindInMapVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + } + }, + "Type": "AWS::Lambda::Version" + }, + "TrueRef": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "FalseFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FalseFindInMapDeploymentGroup" - } - } - }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "FalseFindInMap" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FalseFindInMapVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - } + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueRefRole", + "Arn" + ] }, - "FalseFindInMapRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "TrueRefAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueRefVersion640128d35d", + "Version" + ] }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueRefDeploymentGroup" + } + } + } + }, + "TrueRefDeploymentGroup": { + "Condition": "FunctionCondition", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Condition": "FunctionCondition", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] }, - "FalseRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "TrueFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Condition": "FunctionCondition", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, - "FalseFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "TrueRefRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TrueRefVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" } + }, + "Type": "AWS::Lambda::Version" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/function_with_disabled_deployment_preference.json b/tests/translator/output/aws-cn/function_with_disabled_deployment_preference.json index 80337bcd2b..ea803e1b48 100644 --- a/tests/translator/output/aws-cn/function_with_disabled_deployment_preference.json +++ b/tests/translator/output/aws-cn/function_with_disabled_deployment_preference.json @@ -1,81 +1,81 @@ { "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_disabled_traffic_hook.json b/tests/translator/output/aws-cn/function_with_disabled_traffic_hook.json index f9a12a7c22..58326e9d1a 100644 --- a/tests/translator/output/aws-cn/function_with_disabled_traffic_hook.json +++ b/tests/translator/output/aws-cn/function_with_disabled_traffic_hook.json @@ -3,7 +3,6 @@ "Description": "Template with preference that does not require a new CodeDeploy Service Role", "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -20,59 +19,89 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionVersionfb53d5c2e6": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "FunctionAliaslive": { "Properties": { "FunctionName": { "Ref": "Function" - } - } - }, - "FunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FunctionVersionfb53d5c2e6", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "DeploymentGroupName": { - "Ref": "FunctionDeploymentGroup" - }, "BeforeAllowTrafficHook": { "Ref": "preTrafficHook" + }, + "DeploymentGroupName": { + "Ref": "FunctionDeploymentGroup" } } + } + }, + "FunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery1Minute" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/custom-codedeploy-servicerole" + } }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", "Properties": { - "Name": "live", "FunctionName": { "Ref": "Function" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionVersionfb53d5c2e6", - "Version" - ] } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" }, "preTrafficHook": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", "S3Key": "key" }, - "FunctionName": "CodeDeployHook_preTrafficHook", - "Handler": "hook.lambda_handler", - "Role": { - "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/lambda-role" - }, - "Runtime": "python3.7", - "Timeout": 5, "Environment": { "Variables": { "NewVersion": { @@ -80,27 +109,24 @@ } } }, + "FunctionName": "CodeDeployHook_preTrafficHook", + "Handler": "hook.lambda_handler", + "Role": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/lambda-role" + }, + "Runtime": "python3.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "preTrafficHookVersion5e9ab26520": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "preTrafficHook" - } - } + ], + "Timeout": 5 + }, + "Type": "AWS::Lambda::Function" }, "preTrafficHookAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { - "Name": "live", "FunctionName": { "Ref": "preTrafficHook" }, @@ -109,45 +135,19 @@ "preTrafficHookVersion5e9ab26520", "Version" ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "FunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "preTrafficHookVersion5e9ab26520": { + "DeletionPolicy": "Retain", "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery1Minute" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/custom-codedeploy-servicerole" + "FunctionName": { + "Ref": "preTrafficHook" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_dlq.json b/tests/translator/output/aws-cn/function_with_dlq.json index 3c006a0aff..288b92689d 100644 --- a/tests/translator/output/aws-cn/function_with_dlq.json +++ b/tests/translator/output/aws-cn/function_with_dlq.json @@ -1,34 +1,34 @@ { "Resources": { - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "MySnsDlqLambdaFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DeadLetterConfig": { + "TargetArn": "arn" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MySnsDlqLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": "arn", - "Effect": "Allow" - } - ] - } - } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MySnsDlqLambdaFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -41,62 +41,45 @@ ] } } - ] - } - } - }, - "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": "arn", - "Effect": "Allow" + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": "arn" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "DeadLetterConfig": { + "TargetArn": "arn" + }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -104,43 +87,60 @@ "Arn" ] }, - "DeadLetterConfig": { - "TargetArn": "arn" - }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "MySqsDlqLambdaFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySnsDlqLambdaFunctionRole", - "Arn" - ] - }, - "DeadLetterConfig": { - "TargetArn": "arn" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Effect": "Allow", + "Resource": "arn" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" + } + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/function_with_ephemeral_storage.json b/tests/translator/output/aws-cn/function_with_ephemeral_storage.json index a8a252b0f3..9a0aee8a1d 100644 --- a/tests/translator/output/aws-cn/function_with_ephemeral_storage.json +++ b/tests/translator/output/aws-cn/function_with_ephemeral_storage.json @@ -1,123 +1,123 @@ { + "Parameters": { + "EphemeralStorageSizeRef": { + "Type": "Number" + } + }, "Resources": { "FunctionWithIntrinsicRef": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + }, "EphemeralStorage": { "Size": { "Ref": "EphemeralStorageSizeRef" } - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithIntrinsicRefRole", + "FunctionWithIntrinsicRefRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionWithIntrinsicRefRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "EphemeralStorage": { - "Size": 1024 - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - } - }, - "Parameters": { - "EphemeralStorageSizeRef": { - "Type": "Number" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_event_bridge_rule_state.json b/tests/translator/output/aws-cn/function_with_event_bridge_rule_state.json index 9ec9cc0849..8067f33f07 100644 --- a/tests/translator/output/aws-cn/function_with_event_bridge_rule_state.json +++ b/tests/translator/output/aws-cn/function_with_event_bridge_rule_state.json @@ -1,118 +1,118 @@ { - "Resources": { - "TestBucket": { - "Type": "AWS::S3::Bucket", - "Properties": { - "BucketName": "test-bucket" - } - }, - "TestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return 'Hello from Lambda!';\n};\n" - }, - "FunctionName": "test-function", - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "TestFunctionRole", - "Arn" - ] + "Resources": { + "TestBucket": { + "Properties": { + "BucketName": "test-bucket" + }, + "Type": "AWS::S3::Bucket" }, - "Runtime": "nodejs16.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "TestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "TestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return 'Hello from Lambda!';\n};\n" + }, + "FunctionName": "test-function", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "TestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs16.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] - } - } - ] + }, + "Type": "AWS::Lambda::Function" }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "TestFunctionTestEventBridgeRule": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "source": [ - "aws.s3" - ], - "detail-type": [ - "Object Created" - ], - "detail": { - "bucket": { - "name": [ - "test-bucket" - ] + "TestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "object": { - "key": [ - { - "prefix": "/" - } - ] - } - } + "Type": "AWS::IAM::Role" }, - "State": "ENABLED", - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "TestFunction", - "Arn" - ] + "TestFunctionTestEventBridgeRule": { + "Properties": { + "EventPattern": { + "detail": { + "bucket": { + "name": [ + "test-bucket" + ] + }, + "object": { + "key": [ + { + "prefix": "/" + } + ] + } + }, + "detail-type": [ + "Object Created" + ], + "source": [ + "aws.s3" + ] + }, + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "TestFunction", + "Arn" + ] + }, + "Id": "TestFunctionTestEventBridgeRuleLambdaTarget" + } + ] }, - "Id": "TestFunctionTestEventBridgeRuleLambdaTarget" - } - ] - } - }, - "TestFunctionTestEventBridgeRulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "TestFunction" + "Type": "AWS::Events::Rule" }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "TestFunctionTestEventBridgeRule", - "Arn" - ] + "TestFunctionTestEventBridgeRulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TestFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "TestFunctionTestEventBridgeRule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" } - } } - } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_event_dest.json b/tests/translator/output/aws-cn/function_with_event_dest.json index b719a2dc1b..07888cb6cd 100644 --- a/tests/translator/output/aws-cn/function_with_event_dest.json +++ b/tests/translator/output/aws-cn/function_with_event_dest.json @@ -1,369 +1,369 @@ { "Conditions": { - "TopicCreationEnabled": { - "Fn::Equals": [ - { - "Ref": "CreateSNSTopic" - }, - true - ] - }, "NOTQueueCreationDisabled2da03e5b6f": { "Fn::Not": [ { "Condition": "QueueCreationDisabled" } ] - }, + }, "QueueCreationDisabled": { "Fn::Equals": [ { "Ref": "UseExistingQueue" - }, + }, + true + ] + }, + "TopicCreationEnabled": { + "Fn::Equals": [ + { + "Ref": "CreateSNSTopic" + }, true ] } - }, + }, "Parameters": { - "UseExistingQueue": { - "Default": true, - "Type": "String", - "AllowedValues": [ - true, - false - ] - }, "CreateSNSTopic": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, + ], + "Default": true, + "Type": "String" + }, "SQSArn": { - "Default": "my-sqs-arn", + "Default": "my-sqs-arn", + "Type": "String" + }, + "UseExistingQueue": { + "AllowedValues": [ + true, + false + ], + "Default": true, "Type": "String" } - }, + }, "Resources": { - "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", + "DestinationLambda": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "DestinationLambdaRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DestinationLambdaRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", - { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - }, - "my-sqs-arn" - ] - }, - "Effect": "Allow" - } - ] - } - }, + ], + "Tags": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "sns:publish", - "Resource": { - "Fn::If": [ - "TopicCreationEnabled", - { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - }, - "SOME-SNS-ARN" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {}, - "Condition": "NOTQueueCreationDisabled2da03e5b6f" - }, - "SNSSubscription": { - "Type": "AWS::SNS::Subscription", + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunction2": { "Properties": { - "Endpoint": "example@example.com", - "Protocol": "email", - "TopicArn": { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - } - }, - "Condition": "TopicCreationEnabled" - }, - "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunction2EventInvokeConfig": { "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { - "OnSuccess": { - "Destination": { - "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", - { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - }, - "my-sqs-arn" - ] - } - }, "OnFailure": { + "Destination": "event-bus-arn" + }, + "OnSuccess": { "Destination": { - "Fn::If": [ - "TopicCreationEnabled", - { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - }, - "SOME-SNS-ARN" + "Fn::GetAtt": [ + "DestinationLambda", + "Arn" ] } } - }, + }, "FunctionName": { - "Ref": "MyTestFunction" - }, + "Ref": "MyTestFunction2" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - } - }, + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, "MyTestFunction2Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunction2EventInvokeConfigOnSuccessLambdaPolicy", "PolicyDocument": { "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "DestinationLambda", + "DestinationLambda", "Arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunction2EventInvokeConfigOnSuccessLambdaPolicy" + }, { - "PolicyName": "MyTestFunction2EventInvokeConfigOnFailureEventBridgePolicy", "PolicyDocument": { "Statement": [ { - "Action": "events:PutEvents", - "Resource": "event-bus-arn", - "Effect": "Allow" + "Action": "events:PutEvents", + "Effect": "Allow", + "Resource": "event-bus-arn" } ] - } + }, + "PolicyName": "MyTestFunction2EventInvokeConfigOnFailureEventBridgePolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "DestinationLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "DestinationLambdaRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunction2EventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunctionEventInvokeConfig": { "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { + "OnFailure": { + "Destination": { + "Fn::If": [ + "TopicCreationEnabled", + { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + }, + "SOME-SNS-ARN" + ] + } + }, "OnSuccess": { "Destination": { - "Fn::GetAtt": [ - "DestinationLambda", - "Arn" + "Fn::If": [ + "NOTQueueCreationDisabled2da03e5b6f", + { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + }, + "my-sqs-arn" ] } - }, - "OnFailure": { - "Destination": "event-bus-arn" } - }, + }, "FunctionName": { - "Ref": "MyTestFunction2" - }, + "Ref": "MyTestFunction" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - } - }, - "DestinationLambdaRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, + "MyTestFunctionEventInvokeConfigOnFailureTopic": { + "Condition": "TopicCreationEnabled", + "Properties": {}, + "Type": "AWS::SNS::Topic" + }, + "MyTestFunctionEventInvokeConfigOnSuccessQueue": { + "Condition": "NOTQueueCreationDisabled2da03e5b6f", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "MyTestFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyTestFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Effect": "Allow", + "Resource": { + "Fn::If": [ + "NOTQueueCreationDisabled2da03e5b6f", + { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + }, + "my-sqs-arn" + ] + } + } + ] + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:publish", + "Effect": "Allow", + "Resource": { + "Fn::If": [ + "TopicCreationEnabled", + { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + }, + "SOME-SNS-ARN" + ] + } + } + ] + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunctionEventInvokeConfigOnFailureTopic": { - "Type": "AWS::SNS::Topic", - "Properties": {}, - "Condition": "TopicCreationEnabled" + ] + }, + "Type": "AWS::IAM::Role" + }, + "SNSSubscription": { + "Condition": "TopicCreationEnabled", + "Properties": { + "Endpoint": "example@example.com", + "Protocol": "email", + "TopicArn": { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + } + }, + "Type": "AWS::SNS::Subscription" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_event_dest_basic.json b/tests/translator/output/aws-cn/function_with_event_dest_basic.json index 01a3440e10..3d77cee767 100644 --- a/tests/translator/output/aws-cn/function_with_event_dest_basic.json +++ b/tests/translator/output/aws-cn/function_with_event_dest_basic.json @@ -1,149 +1,149 @@ { "Parameters": { "SNSArn": { - "Default": "my-sns-arn", + "Default": "my-sns-arn", "Type": "String" } - }, + }, "Resources": { + "MyTestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MyTestFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MyTestFunctionVersiondaf9da458d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyTestFunctionEventInvokeConfig": { + "DependsOn": [ + "MyTestFunctionAliaslive" + ], + "Properties": { + "DestinationConfig": { + "OnFailure": { + "Destination": "my-sns-arn" + }, + "OnSuccess": { + "Destination": { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + } + } + }, + "FunctionName": { + "Ref": "MyTestFunction" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, + "Qualifier": "live" + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sns:publish", - "Resource": "my-sns-arn", - "Effect": "Allow" + "Action": "sns:publish", + "Effect": "Allow", + "Resource": "my-sns-arn" } ] - } + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", - "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, - "DestinationConfig": { - "OnSuccess": { - "Destination": { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - } - }, - "OnFailure": { - "Destination": "my-sns-arn" - } - }, - "FunctionName": { - "Ref": "MyTestFunction" - }, - "Qualifier": "live" - }, - "DependsOn": [ - "MyTestFunctionAliaslive" - ] - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MyTestFunctionVersiondaf9da458d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MyTestFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "MyTestFunctionVersiondaf9da458d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MyTestFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_event_dest_conditional.json b/tests/translator/output/aws-cn/function_with_event_dest_conditional.json index e90a0e5853..f1762704db 100644 --- a/tests/translator/output/aws-cn/function_with_event_dest_conditional.json +++ b/tests/translator/output/aws-cn/function_with_event_dest_conditional.json @@ -1,266 +1,266 @@ { "Conditions": { + "FunctionCondition": { + "Fn::Equals": [ + true, + false + ] + }, "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6": { "Fn::And": [ { "Condition": { "Condition": "FunctionCondition" } - }, + }, { "Condition": { "Condition": "NOTQueueCreationDisabled2da03e5b6f" } } ] - }, - "QueueCreationDisabled": { + }, + "FunctionInlineEnabled": { "Fn::Equals": [ - { - "Ref": "UseExistingQueue" - }, - true + true, + false ] - }, + }, "NOTQueueCreationDisabled2da03e5b6f": { "Fn::Not": [ { "Condition": "QueueCreationDisabled" } ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - false - ] - }, - "FunctionInlineEnabled": { + }, + "QueueCreationDisabled": { "Fn::Equals": [ - true, - false + { + "Ref": "UseExistingQueue" + }, + true ] } - }, + }, "Parameters": { + "SQSArn": { + "Default": "my-sqs-arn", + "Type": "String" + }, "UseExistingQueue": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, - "SQSArn": { - "Default": "my-sqs-arn", + ], + "Default": true, "Type": "String" } - }, + }, "Resources": { + "DestinationLambda": { + "Condition": "FunctionInlineEnabled", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "DestinationLambdaRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "DestinationLambdaRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionInlineEnabled", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionInlineEnabled" - }, - "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {}, - "Condition": "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6" - }, + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunction": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + "Condition": "FunctionCondition", "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { - "OnSuccess": { + "OnFailure": { "Destination": { "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", + "FunctionInlineEnabled", { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "DestinationLambda", "Arn" ] - }, - "my-sqs-arn" + }, + "some-function-arn" ] } - }, - "OnFailure": { + }, + "OnSuccess": { "Destination": { "Fn::If": [ - "FunctionInlineEnabled", + "NOTQueueCreationDisabled2da03e5b6f", { "Fn::GetAtt": [ - "DestinationLambda", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, - "some-function-arn" + }, + "my-sqs-arn" ] } } - }, + }, "FunctionName": { "Ref": "MyTestFunction" - }, + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - }, - "Condition": "FunctionCondition" - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "Condition": "FunctionCondition" - }, - "DestinationLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "DestinationLambdaRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "Condition": "FunctionInlineEnabled" - }, + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, + "MyTestFunctionEventInvokeConfigOnSuccessQueue": { + "Condition": "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", + "NOTQueueCreationDisabled2da03e5b6f", { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, + }, "my-sqs-arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureLambdaPolicy", "PolicyDocument": { "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::If": [ - "FunctionInlineEnabled", + "FunctionInlineEnabled", { "Fn::GetAtt": [ - "DestinationLambda", + "DestinationLambda", "Arn" ] - }, + }, "some-function-arn" ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureLambdaPolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_event_filtering.json b/tests/translator/output/aws-cn/function_with_event_filtering.json index a32d899586..70df8b1429 100644 --- a/tests/translator/output/aws-cn/function_with_event_filtering.json +++ b/tests/translator/output/aws-cn/function_with_event_filtering.json @@ -1,19 +1,9 @@ { "Resources": { - "KinesisStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } - }, "DynamoDBTable": { "Type": "AWS::DynamoDB::Table" }, - "MySqsQueue": { - "Type": "AWS::SQS::Queue" - }, "FilteredEventsFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -33,101 +23,10 @@ "Value": "SAM" } ] - } - }, - "FilteredEventsFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Policies": [ - { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "ec2:CreateNetworkInterface", - "ec2:DescribeNetworkInterfaces", - "ec2:DeleteNetworkInterface", - "ec2:DescribeVpcs", - "ec2:DescribeSubnets", - "ec2:DescribeSecurityGroups" - ], - "Effect": "Allow", - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "SelfManagedKafkaExecutionRolePolicy" - }, - { - "PolicyName": "SamAutoGeneratedAMQPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "mq:DescribeBroker" - ], - "Effect": "Allow", - "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" - } - } - ] - } - } - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "FilteredEventsFunctionDynamoDBStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": { "Fn::GetAtt": [ @@ -135,21 +34,21 @@ "StreamArn" ] }, - "FunctionName": { - "Ref": "FilteredEventsFunction" - }, - "StartingPosition": "TRIM_HORIZON", "FilterCriteria": { "Filters": [ { "Pattern": "{ \"dynamodb\": { \"NewImage\": { \"value\": { \"S\": [\"test\"] } } } }" } ] - } - } + }, + "FunctionName": { + "Ref": "FilteredEventsFunction" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "FilteredEventsFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": { "Fn::GetAtt": [ @@ -157,10 +56,6 @@ "Arn" ] }, - "FunctionName": { - "Ref": "FilteredEventsFunction" - }, - "StartingPosition": "LATEST", "FilterCriteria": { "Filters": [ { @@ -170,59 +65,53 @@ "Pattern": "{\"name2\": \"value2\"}" } ] - } - } - }, - "FilteredEventsFunctionMySqsEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Fn::GetAtt": [ - "MySqsQueue", - "Arn" - ] }, "FunctionName": { "Ref": "FilteredEventsFunction" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMSKEvent": { + "Properties": { + "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMSKEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, "StartingPosition": "LATEST", "Topics": [ "MyDummyTestTopic" - ], + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMyKafkaEvent": { + "Properties": { "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMyKafkaEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, - "Topics": [ - "Topic1" - ], + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092" + ] + } + }, "SourceAccessConfigurations": [ { "Type": "SASL_SCRAM_512_AUTH", @@ -237,26 +126,22 @@ "URI": "security_group:sg-67890" } ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092" - ] - } - }, + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, @@ -268,15 +153,130 @@ "Type": "BASIC_AUTH", "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" } - ], + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMySqsEvent": { + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MySqsQueue", + "Arn" + ] + }, "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] + }, + "FunctionName": { + "Ref": "FilteredEventsFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "ec2:CreateNetworkInterface", + "ec2:DescribeNetworkInterfaces", + "ec2:DeleteNetworkInterface", + "ec2:DescribeVpcs", + "ec2:DescribeSubnets", + "ec2:DescribeSecurityGroups" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "SelfManagedKafkaExecutionRolePolicy" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "mq:DescribeBroker" + ], + "Effect": "Allow", + "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" + }, + { + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" + } + } + ] + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" + } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "KinesisStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "MySqsQueue": { + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_event_schedule_state.json b/tests/translator/output/aws-cn/function_with_event_schedule_state.json index 7f816444cd..b2e4565597 100644 --- a/tests/translator/output/aws-cn/function_with_event_schedule_state.json +++ b/tests/translator/output/aws-cn/function_with_event_schedule_state.json @@ -1,176 +1,176 @@ { - "Parameters": { - "ScheduleState": { - "Type": "String", - "Default": "Disabled" - } - }, - "Resources": { - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ScheduledFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Parameters": { + "ScheduleState": { + "Default": "Disabled", + "Type": "String" + } + }, + "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "ScheduledFunctionSchedule1": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": "Enabled", - "Targets": [ + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] - }, - "Id": "ScheduledFunctionSchedule1LambdaTarget" + } } - ] - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "ScheduledFunctionSchedule1Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule1", - "Arn" - ] + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule1": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": "Enabled", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule1LambdaTarget" } - } + ] }, - "ScheduledFunctionSchedule2": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": { - "Fn::Sub": "Enabled" - }, - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - }, - "Id": "ScheduledFunctionSchedule2LambdaTarget" - } + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule1Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule1", + "Arn" ] } }, - "ScheduledFunctionSchedule2Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule2", - "Arn" - ] + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionSchedule2": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": { + "Fn::Sub": "Enabled" + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule2LambdaTarget" } - } + ] }, - "ScheduledFunctionSchedule3": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": { - "Ref": "ScheduleState" - }, - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - }, - "Id": "ScheduledFunctionSchedule3LambdaTarget" - } + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule2Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule2", + "Arn" ] } }, - "ScheduledFunctionSchedule3Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule3", - "Arn" - ] + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionSchedule3": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": { + "Ref": "ScheduleState" + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule3LambdaTarget" } + ] + }, + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule3Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule3", + "Arn" + ] } - } + }, + "Type": "AWS::Lambda::Permission" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/function_with_event_source_mapping.json b/tests/translator/output/aws-cn/function_with_event_source_mapping.json index 0a042dd072..c662f909fb 100644 --- a/tests/translator/output/aws-cn/function_with_event_source_mapping.json +++ b/tests/translator/output/aws-cn/function_with_event_source_mapping.json @@ -3,60 +3,124 @@ "Parameters": { "MyBatchingWindowParam": { "Default": 45, - "Type": "Number", - "Description": "parameter for batching window in seconds" + "Description": "parameter for batching window in seconds", + "Type": "Number" } }, "Resources": { - "MySqsQueue": { - "Type": "AWS::SQS::Queue" - }, - "MySnsTopic": { - "Type": "AWS::SNS::Topic" - }, - "MyFunctionForBatchingExampleStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": 20, - "EventSourceArn": { - "Fn::GetAtt": [ - "KinesisStream", - "Arn" - ] - }, - "FunctionName": { - "Ref": "MyFunctionForBatchingExample" - }, - "StartingPosition": "LATEST" - } - }, "DynamoDBTable": { - "Type": "AWS::DynamoDB::Table", "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, "StreamSpecification": { "StreamViewType": "NEW_IMAGE" + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "KinesisStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "KinesisStream1": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "MyFunctionForBatchingExample": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "AttributeDefinitions": [ + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionForBatchingExampleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "AttributeName": "id", - "AttributeType": "S" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionForBatchingExampleDynamoDBStreamEvent": { + "Properties": { + "BatchSize": 100, + "BisectBatchOnFunctionError": true, + "DestinationConfig": { + "OnFailure": { + "Destination": { + "Fn::GetAtt": [ + "MySqsQueue", + "Arn" + ] + } } + }, + "EventSourceArn": { + "Fn::GetAtt": [ + "DynamoDBTable", + "StreamArn" + ] + }, + "FunctionName": { + "Ref": "MyFunctionForBatchingExample" + }, + "FunctionResponseTypes": [ + "ReportBatchItemFailures" ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } + "MaximumBatchingWindowInSeconds": { + "Ref": "MyBatchingWindowParam" + }, + "MaximumRecordAgeInSeconds": 86400, + "MaximumRetryAttempts": 100, + "ParallelizationFactor": 8, + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyFunctionForBatchingExampleRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", @@ -64,13 +128,13 @@ ], "Policies": [ { - "PolicyName": "MyFunctionForBatchingExampleRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -83,14 +147,13 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MyFunctionForBatchingExampleRolePolicy0" }, { - "PolicyName": "MyFunctionForBatchingExampleDynamoDBStreamEventSQSPolicy", "PolicyDocument": { "Statement": [ { @@ -104,116 +167,58 @@ } } ] - } + }, + "PolicyName": "MyFunctionForBatchingExampleDynamoDBStreamEventSQSPolicy" }, { - "PolicyDocument": { - "Statement": [ - { - "Action": "sns:publish", - "Effect": "Allow", - "Resource": { - "Ref": "MySnsTopic" - } - } - ] - }, - "PolicyName": "MyFunctionForBatchingExampleStreamEventSNSPolicy" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:publish", + "Effect": "Allow", + "Resource": { + "Ref": "MySnsTopic" + } + } + ] + }, + "PolicyName": "MyFunctionForBatchingExampleStreamEventSNSPolicy" } ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "KinesisStream1": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionForBatchingExampleDynamoDBStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyFunctionForBatchingExampleStream": { "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "MyBatchingWindowParam" + "EventSourceArn": { + "Fn::GetAtt": [ + "KinesisStream", + "Arn" + ] }, "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "MaximumRecordAgeInSeconds": 86400, - "BatchSize": 100, + "MaximumBatchingWindowInSeconds": 20, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEvent": { + "Properties": { "DestinationConfig": { "OnFailure": { "Destination": { - "Fn::GetAtt": [ - "MySqsQueue", - "Arn" - ] + "Ref": "MySnsTopic" } } }, - "EventSourceArn": { - "Fn::GetAtt": [ - "DynamoDBTable", - "StreamArn" - ] - }, - "StartingPosition": "TRIM_HORIZON", - "ParallelizationFactor": 8, - "MaximumRetryAttempts": 100, - "BisectBatchOnFunctionError": true, - "TumblingWindowInSeconds": 60, - "FunctionResponseTypes": ["ReportBatchItemFailures"] - } - }, - "MyFunctionForBatchingExample": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionForBatchingExampleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionForBatchingExampleStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "MyBatchingWindowParam" - }, "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -223,22 +228,15 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "StartingPosition": "LATEST", - "DestinationConfig": { - "OnFailure": { - "Destination": { - "Ref": "MySnsTopic" - } - } - } - } - }, - "MyFunctionForBatchingExampleStreamEventWithoutDestinationConfigType": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { "MaximumBatchingWindowInSeconds": { "Ref": "MyBatchingWindowParam" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEventWithEmptyDestinationConfig": { + "Properties": { "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -248,22 +246,22 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "StartingPosition": "LATEST", - "DestinationConfig": { - "OnFailure": { - "Destination": { - "Ref": "MySnsTopic" - } - } - } - } - }, - "MyFunctionForBatchingExampleStreamEventWithEmptyDestinationConfig": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { "MaximumBatchingWindowInSeconds": { "Ref": "MyBatchingWindowParam" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEventWithoutDestinationConfigType": { + "Properties": { + "DestinationConfig": { + "OnFailure": { + "Destination": { + "Ref": "MySnsTopic" + } + } + }, "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -273,14 +271,18 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, + "MaximumBatchingWindowInSeconds": { + "Ref": "MyBatchingWindowParam" + }, "StartingPosition": "LATEST" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "KinesisStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } + "MySnsTopic": { + "Type": "AWS::SNS::Topic" + }, + "MySqsQueue": { + "Type": "AWS::SQS::Queue" } } } diff --git a/tests/translator/output/aws-cn/function_with_file_system_config.json b/tests/translator/output/aws-cn/function_with_file_system_config.json index 9fc9269ebb..89379b52dc 100644 --- a/tests/translator/output/aws-cn/function_with_file_system_config.json +++ b/tests/translator/output/aws-cn/function_with_file_system_config.json @@ -1,115 +1,115 @@ { + "Description": "SAM + Lambda + EFS", + "Parameters": { + "ExistingEfsFileSystem": { + "Type": "String" + }, + "SecurityGroupIds": { + "Description": "Security Group IDs that Lambda will use", + "Type": "List" + }, + "VpcSubnetIds": { + "Description": "VPC Subnet IDs that Lambda will use", + "Type": "List" + } + }, "Resources": { + "AccessPoint": { + "Properties": { + "FileSystemId": { + "Ref": "EfsFileSystem" + } + }, + "Type": "AWS::EFS::AccessPoint" + }, "EfsFileSystem": { "Type": "AWS::EFS::FileSystem" - }, + }, "LambdaFunctionWithEfs": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "const fs = require('fs')\nconst path = require('path')\nconst efsMountPath = '/mnt/efs'\n\nexports.handler = async (event, context, callback) => {\nconst directory = path.join(efsMountPath, event.body)\nconst files = fs.readdirSync(directory)\nreturn files\n}\n" - }, - "VpcConfig": { - "SubnetIds": { - "Ref": "VpcSubnetIds" - }, - "SecurityGroupIds": { - "Ref": "SecurityGroupIds" - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "LambdaFunctionWithEfsRole", - "Arn" - ] - }, - "Timeout": 3, + }, "FileSystemConfigs": [ { "Arn": { "Fn::GetAtt": [ - "AccessPoint", + "AccessPoint", "Arn" ] - }, + }, "LocalMountPath": "/mnt/EFS" } - ], - "Runtime": "nodejs12.x" - } - }, - "MountTarget": { - "Type": "AWS::EFS::MountTarget", - "Properties": { - "SubnetId": "subnet-abc123", - "FileSystemId": { - "Ref": "EfsFileSystem" - }, - "SecurityGroups": { - "Ref": "SecurityGroupIds" + ], + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionWithEfsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3, + "VpcConfig": { + "SecurityGroupIds": { + "Ref": "SecurityGroupIds" + }, + "SubnetIds": { + "Ref": "VpcSubnetIds" + } } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "LambdaFunctionWithEfsRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "AccessPoint": { - "Type": "AWS::EFS::AccessPoint", + }, + "Type": "AWS::IAM::Role" + }, + "MountTarget": { "Properties": { "FileSystemId": { "Ref": "EfsFileSystem" - } - } - } - }, - "Description": "SAM + Lambda + EFS", - "Parameters": { - "ExistingEfsFileSystem": { - "Type": "String" - }, - "VpcSubnetIds": { - "Type": "List", - "Description": "VPC Subnet IDs that Lambda will use" - }, - "SecurityGroupIds": { - "Type": "List", - "Description": "Security Group IDs that Lambda will use" + }, + "SecurityGroups": { + "Ref": "SecurityGroupIds" + }, + "SubnetId": "subnet-abc123" + }, + "Type": "AWS::EFS::MountTarget" } } } diff --git a/tests/translator/output/aws-cn/function_with_function_url_config.json b/tests/translator/output/aws-cn/function_with_function_url_config.json index b33ef5b0d8..affe30906a 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,59 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -84,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -95,7 +55,47 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json b/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json index 155784e64f..4a15d2f1f6 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config_and_autopublishalias.json @@ -1,125 +1,125 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, - "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Handler": "index.handler", - "MemorySize": 1024, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Timeout": 3, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, + "Resources": { + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "MyFunctionVersion7eab81fa22": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - } - } + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, - "MyFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MyFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MyFunctionVersion7eab81fa22", - "Version" - ] - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MyFunction" }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunctionAliaslive" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } + "FunctionVersion": { + "Fn::GetAtt": [ + "MyFunctionVersion7eab81fa22", + "Version" + ] }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunctionAliaslive" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunctionAliaslive" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunctionAliaslive" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionVersion7eab81fa22": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MyFunction" } + }, + "Type": "AWS::Lambda::Version" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/function_with_function_url_config_conditions.json b/tests/translator/output/aws-cn/function_with_function_url_config_conditions.json index 64d3346dd1..5cb30218d3 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config_conditions.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config_conditions.json @@ -11,7 +11,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Condition": "MyCondition", "Properties": { "Code": { @@ -28,62 +27,20 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Condition": "MyCondition", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "MyCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -96,7 +53,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -107,7 +65,49 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Condition": "MyCondition", + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_function_url_config_with_iam_authorization_type.json b/tests/translator/output/aws-cn/function_with_function_url_config_with_iam_authorization_type.json index 9e689d942d..6f0af08b37 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config_with_iam_authorization_type.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config_with_iam_authorization_type.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,48 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "AWS_IAM", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -73,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -84,7 +55,36 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "AWS_IAM", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_function_url_config_with_intrinsics.json b/tests/translator/output/aws-cn/function_with_function_url_config_with_intrinsics.json index 44841b93f0..c5766cf83d 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config_with_intrinsics.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config_with_intrinsics.json @@ -1,22 +1,21 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { - "AuthorizationTypeRef": { - "Type": "String", - "Default": "NONE" + "AllowMethodsRef": { + "Default": "GET", + "Type": "CommaDelimitedList" }, "AllowOriginsRef": { - "Type": "CommaDelimitedList", - "Default": "https://example.com" + "Default": "https://example.com", + "Type": "CommaDelimitedList" }, - "AllowMethodsRef": { - "Type": "CommaDelimitedList", - "Default": "GET" + "AuthorizationTypeRef": { + "Default": "NONE", + "Type": "String" } }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -32,39 +31,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": { - "Ref": "AuthorizationTypeRef" - }, - "Cors": { - "AllowOrigins": { - "Ref": "AllowOriginsRef" - }, - "AllowMethods": { - "Ref": "AllowMethodsRef" - } - } - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -77,7 +56,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -88,7 +68,27 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": { + "Ref": "AuthorizationTypeRef" + }, + "Cors": { + "AllowMethods": { + "Ref": "AllowMethodsRef" + }, + "AllowOrigins": { + "Ref": "AllowOriginsRef" + } + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_function_url_config_without_cors_config.json b/tests/translator/output/aws-cn/function_with_function_url_config_without_cors_config.json index 72dd8e5c8d..b20af083f9 100644 --- a/tests/translator/output/aws-cn/function_with_function_url_config_without_cors_config.json +++ b/tests/translator/output/aws-cn/function_with_function_url_config_without_cors_config.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,40 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE" - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,7 +55,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_global_layers.json b/tests/translator/output/aws-cn/function_with_global_layers.json index e0fcdb520c..d9b16fac45 100644 --- a/tests/translator/output/aws-cn/function_with_global_layers.json +++ b/tests/translator/output/aws-cn/function_with_global_layers.json @@ -1,19 +1,38 @@ { "Resources": { - "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "ManyLayersFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:layer1:1", + "arn:aws:lambda:us-east-1:123456789101:layer:layer2:1", + "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" ], + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ManyLayersFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -26,39 +45,20 @@ ] } } - ] - } - } - }, - "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "python3.6", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:layer1:1", - "arn:aws:lambda:us-east-1:123456789101:layer:layer2:1", - "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" ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_intrinsic_architecture.json b/tests/translator/output/aws-cn/function_with_intrinsic_architecture.json index 798b131fcb..725973cbff 100644 --- a/tests/translator/output/aws-cn/function_with_intrinsic_architecture.json +++ b/tests/translator/output/aws-cn/function_with_intrinsic_architecture.json @@ -1,14 +1,16 @@ { "Parameters": { "ArchitectureRef": { - "Type": "String", - "Default": "arm64" + "Default": "arm64", + "Type": "String" } }, "Resources": { "FunctionWithArchitecturesIntrinsic": { - "Type": "AWS::Lambda::Function", "Properties": { + "Architectures": { + "Ref": "ArchitectureRef" + }, "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" @@ -23,23 +25,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ], - "Architectures": { - "Ref": "ArchitectureRef" - } - } + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithArchitecturesIntrinsicRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -52,7 +50,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -63,7 +62,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_kmskeyarn.json b/tests/translator/output/aws-cn/function_with_kmskeyarn.json index c26fd25065..ee55a42ee4 100644 --- a/tests/translator/output/aws-cn/function_with_kmskeyarn.json +++ b/tests/translator/output/aws-cn/function_with_kmskeyarn.json @@ -1,19 +1,32 @@ { "Resources": { - "FunctionWithKeyArnRole": { - "Type": "AWS::IAM::Role", + "FunctionWithKeyArn": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "KmsKeyArn": "thisIsaKey", + "Role": { + "Fn::GetAtt": [ + "FunctionWithKeyArnRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithKeyArnRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -26,24 +39,50 @@ ] } } - ] - } - } - }, - "FunctionWithReferenceToKeyArnRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithReferenceToKeyArn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "KmsKeyArn": { + "Ref": "myKey" + }, + "Role": { + "Fn::GetAtt": [ + "FunctionWithReferenceToKeyArnRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithReferenceToKeyArnRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,82 +95,43 @@ ] } } - ] - } - } - }, - "FunctionWithKeyArn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "KmsKeyArn": "thisIsaKey", - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithKeyArnRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ] + }, + "Type": "AWS::IAM::Role" }, "myKey": { - "Type": "AWS::KMS::Key", "Properties": { + "Description": "A sample key", "KeyPolicy": { - "Version": "2012-10-17", "Id": "key-default-1", "Statement": [ { "Action": [ "kms:Create*" ], - "Sid": "Allow administration of the key", - "Resource": "*", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:user/Alice" - } + }, + "Resource": "*", + "Sid": "Allow administration of the key" } - ] - }, - "Description": "A sample key" - } - }, - "FunctionWithReferenceToKeyArn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "KmsKeyArn": { - "Ref": "myKey" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithReferenceToKeyArnRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ], + "Version": "2012-10-17" + } + }, + "Type": "AWS::KMS::Key" } } } diff --git a/tests/translator/output/aws-cn/function_with_layers.json b/tests/translator/output/aws-cn/function_with_layers.json index 7c2004acff..0dec17bbff 100644 --- a/tests/translator/output/aws-cn/function_with_layers.json +++ b/tests/translator/output/aws-cn/function_with_layers.json @@ -1,246 +1,246 @@ { "Resources": { - "MinimalLayerFunction": { - "Type": "AWS::Lambda::Function", + "FunctionLayerWithSubIntrinsic": { "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalLayerFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "MyLayera5167acaba": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "MyLayer" - } - }, - "FunctionReferencesLayer": { - "Type": "AWS::Lambda::Function", - "Properties": { + }, + "Handler": "hello.handler", "Layers": [ { - "Ref": "MyLayera5167acaba" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1" + }, { - "Value": "SAM", - "Key": "lambda:createdBy" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1" } - ], - "Handler": "hello.handler", + ], "Role": { "Fn::GetAtt": [ - "FunctionReferencesLayerRole", + "FunctionLayerWithSubIntrinsicRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "MinimalLayerFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionLayerWithSubIntrinsicRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionReferencesLayerRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionNoLayerVersion": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" ], + "Role": { + "Fn::GetAtt": [ + "FunctionNoLayerVersionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionNoLayerVersionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionLayerWithSubIntrinsic": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ - { - "Fn::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" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionLayerWithSubIntrinsicRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "FunctionNoLayerVersion": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionReferencesLayer": { "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ + }, + "Handler": "hello.handler", + "Layers": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "MyLayera5167acaba" } - ], - "Handler": "hello.handler", + ], "Role": { "Fn::GetAtt": [ - "FunctionNoLayerVersionRole", + "FunctionReferencesLayerRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "FunctionNoLayerVersionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionReferencesLayerRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionLayerWithSubIntrinsicRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalLayerFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" ], + "Role": { + "Fn::GetAtt": [ + "MinimalLayerFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalLayerFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_many_layers.json b/tests/translator/output/aws-cn/function_with_many_layers.json index 2bff7ff8fa..2766dd64e6 100644 --- a/tests/translator/output/aws-cn/function_with_many_layers.json +++ b/tests/translator/output/aws-cn/function_with_many_layers.json @@ -1,81 +1,81 @@ { "Resources": { - "MyLayera5167acaba": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "MyLayer" - } - }, - "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "ManyLayersFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:z:1", + { + "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" + }, + "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" + }, + { + "Ref": "MyLayera5167acaba" + } ], + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ManyLayersFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:z:1", - { - "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" - }, - "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", - { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" - }, - { - "Ref": "MyLayera5167acaba" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_mq_virtual_host.json b/tests/translator/output/aws-cn/function_with_mq_virtual_host.json index 3f19f99cda..4898e21c13 100644 --- a/tests/translator/output/aws-cn/function_with_mq_virtual_host.json +++ b/tests/translator/output/aws-cn/function_with_mq_virtual_host.json @@ -1,7 +1,6 @@ { "Resources": { "MQFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,34 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Type": "VIRTUAL_HOST", + "URI": "vhost_name" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MQFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,14 +60,14 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", "PolicyDocument": { "Statement": [ { @@ -65,7 +85,8 @@ "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" } ] - } + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" } ], "Tags": [ @@ -74,29 +95,8 @@ "Value": "SAM" } ] - } - }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Type": "VIRTUAL_HOST", - "URI": "vhost_name" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_msk.json b/tests/translator/output/aws-cn/function_with_msk.json index d345158a4f..b30aaacf6c 100644 --- a/tests/translator/output/aws-cn/function_with_msk.json +++ b/tests/translator/output/aws-cn/function_with_msk.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyMskStreamProcessor": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,30 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyMskStreamProcessorMyMskEvent": { + "Properties": { + "AmazonManagedKafkaEventSourceConfig": { + "ConsumerGroupId": "consumergroup1" + }, + "EventSourceArn": { + "Fn::Sub": "arn:aws:kafka:${AWS::Region}:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" + }, + "FunctionName": { + "Ref": "MyMskStreamProcessor" + }, + "StartingPosition": "LATEST", + "Topics": [ + "MyDummyTestTopic" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyMskStreamProcessorRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +58,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -54,25 +71,8 @@ "Value": "SAM" } ] - } - }, - "MyMskStreamProcessorMyMskEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Fn::Sub": "arn:aws:kafka:${AWS::Region}:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" - }, - "FunctionName": { - "Ref": "MyMskStreamProcessor" - }, - "StartingPosition": "LATEST", - "Topics": [ - "MyDummyTestTopic" - ], - "AmazonManagedKafkaEventSourceConfig": { - "ConsumerGroupId": "consumergroup1" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_msk_with_intrinsics.json b/tests/translator/output/aws-cn/function_with_msk_with_intrinsics.json index 9e6bf3324d..074ab61f0f 100644 --- a/tests/translator/output/aws-cn/function_with_msk_with_intrinsics.json +++ b/tests/translator/output/aws-cn/function_with_msk_with_intrinsics.json @@ -1,26 +1,25 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { + "ConsumerGroupValue": { + "Default": "consumergroup1", + "Type": "String" + }, "StartingPositionValue": { - "Type": "String", - "Default": "LATEST" + "Default": "LATEST", + "Type": "String" }, "StreamValue": { - "Type": "String", - "Default": "arn:aws:kafka:us-east-1:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" + "Default": "arn:aws:kafka:us-east-1:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", + "Type": "String" }, "TopicsValue": { - "Type": "CommaDelimitedList", - "Default": "Topic" - }, - "ConsumerGroupValue": { - "Type": "String", - "Default": "consumergroup1" + "Default": "Topic", + "Type": "CommaDelimitedList" } }, "Resources": { "MyMskStreamProcessor": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -40,13 +39,34 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyMskStreamProcessorMyMskEvent": { + "Properties": { + "AmazonManagedKafkaEventSourceConfig": { + "ConsumerGroupId": { + "Ref": "ConsumerGroupValue" + } + }, + "EventSourceArn": { + "Ref": "StreamValue" + }, + "FunctionName": { + "Ref": "MyMskStreamProcessor" + }, + "StartingPosition": { + "Ref": "StartingPositionValue" + }, + "Topics": { + "Ref": "TopicsValue" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyMskStreamProcessorRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -59,7 +79,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -71,29 +92,8 @@ "Value": "SAM" } ] - } - }, - "MyMskStreamProcessorMyMskEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Ref": "StreamValue" - }, - "FunctionName": { - "Ref": "MyMskStreamProcessor" - }, - "StartingPosition": { - "Ref": "StartingPositionValue" - }, - "Topics": { - "Ref": "TopicsValue" - }, - "AmazonManagedKafkaEventSourceConfig": { - "ConsumerGroupId": { - "Ref": "ConsumerGroupValue" - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_null_events.json b/tests/translator/output/aws-cn/function_with_null_events.json index 4983f3fc4f..5c3342984f 100644 --- a/tests/translator/output/aws-cn/function_with_null_events.json +++ b/tests/translator/output/aws-cn/function_with_null_events.json @@ -1,7 +1,6 @@ { "Resources": { "FunctionWithNullEvents": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithNullEventsRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,7 +50,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_permissions_boundary.json b/tests/translator/output/aws-cn/function_with_permissions_boundary.json index b71af4f7ba..c52c7cdaa7 100644 --- a/tests/translator/output/aws-cn/function_with_permissions_boundary.json +++ b/tests/translator/output/aws-cn/function_with_permissions_boundary.json @@ -1,58 +1,58 @@ { "Resources": { - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/function_with_policy_templates.json b/tests/translator/output/aws-cn/function_with_policy_templates.json index d6e45817e8..138f8619d8 100644 --- a/tests/translator/output/aws-cn/function_with_policy_templates.json +++ b/tests/translator/output/aws-cn/function_with_policy_templates.json @@ -5,8 +5,7 @@ } }, "Resources": { - "OnePolicyTemplate": { - "Type": "AWS::Lambda::Function", + "AllCombinations": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -15,91 +14,117 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "OnePolicyTemplateRole", + "AllCombinationsRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MultiplePolicyTemplates": { - "Type": "AWS::Lambda::Function", + "AllCombinationsRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MultiplePolicyTemplatesRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "OnePolicyTemplateRole": { - "Type": "AWS::IAM::Role", - "Properties": { "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { - "PolicyName": "OnePolicyTemplateRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "sqs:ChangeMessageVisibility", - "sqs:ChangeMessageVisibilityBatch", - "sqs:DeleteMessage", - "sqs:DeleteMessageBatch", - "sqs:GetQueueAttributes", - "sqs:ReceiveMessage" + "dynamodb:*" ], + "Effect": "Allow", + "Resource": "*" + } + ] + }, + "PolicyName": "AllCombinationsRolePolicy0" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "lambda:InvokeFunction" + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { - "queueName": { - "Fn::Sub": [ - "Some${value}", - { - "value": "KeyId" - } - ] + "functionName": { + "Ref": "FunctionNameParam" } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "AllCombinationsRolePolicy2" } ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MultiplePolicyTemplates": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MultiplePolicyTemplatesRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MultiplePolicyTemplatesRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -112,25 +137,14 @@ ] } } - ] - } - } - }, - "MultiplePolicyTemplatesRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { - "PolicyName": "MultiplePolicyTemplatesRolePolicy0", "PolicyDocument": { "Statement": [ { @@ -142,6 +156,7 @@ "sqs:GetQueueAttributes", "sqs:ReceiveMessage" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -149,20 +164,20 @@ "queueName": "Somekey" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MultiplePolicyTemplatesRolePolicy0" }, { - "PolicyName": "MultiplePolicyTemplatesRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -170,33 +185,23 @@ "functionName": "Some function" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MultiplePolicyTemplatesRolePolicy1" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "AllCombinations": { - "Type": "AWS::Lambda::Function", + "OnePolicyTemplate": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -205,89 +210,84 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "AllCombinationsRole", + "OnePolicyTemplateRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "AllCombinationsRole": { - "Type": "AWS::IAM::Role", + "OnePolicyTemplateRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { - "PolicyName": "AllCombinationsRolePolicy0", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } - }, - { - "PolicyName": "AllCombinationsRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ - "lambda:InvokeFunction" + "sqs:ChangeMessageVisibility", + "sqs:ChangeMessageVisibilityBatch", + "sqs:DeleteMessage", + "sqs:DeleteMessageBatch", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { - "functionName": { - "Ref": "FunctionNameParam" + "queueName": { + "Fn::Sub": [ + "Some${value}", + { + "value": "KeyId" + } + ] } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "OnePolicyTemplateRolePolicy0" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/function_with_request_parameters.json b/tests/translator/output/aws-cn/function_with_request_parameters.json index d5715a3542..a090e04c6b 100644 --- a/tests/translator/output/aws-cn/function_with_request_parameters.json +++ b/tests/translator/output/aws-cn/function_with_request_parameters.json @@ -1,13 +1,69 @@ { "Resources": { + "Api": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "parameters": [ + { + "in": "header", + "name": "Authorization", + "required": true, + "type": "string" + } + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "cacheKeyParameters": [ + "method.request.header.Authorization" + ], + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentd779e9df57": { + "Properties": { + "Description": "RestApi deployment id: d779e9df577321942ace63ca5592fbc8ba6fa9ec", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiParameterFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ApiParameterFunctionRole", @@ -17,66 +73,35 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "NoApiParameterFunctionRole": { - "Type": "AWS::IAM::Role", + "ApiParameterFunctionGetHtmlPermissionProd": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": "Api", + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiDeployment32042a0513": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 32042a0513cd1c4e5c14794b306c4de10ca5c4af", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, "ApiParameterFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,172 +114,147 @@ ] } } - ] - } - } - }, - "NoApiParameterFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "NoApiParameterFunction" + ], + "Version": "2012-10-17" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeployment32042a0513" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" + "Ref": "ApiDeploymentd779e9df57" }, - "StageName": "Prod" - } - }, - "ApiDeploymentd779e9df57": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { "RestApiId": { "Ref": "Api" }, - "Description": "RestApi deployment id: d779e9df577321942ace63ca5592fbc8ba6fa9ec", - "StageName": "Stage" - } + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "Api": { - "Type": "AWS::ApiGateway::RestApi", + "NoApiParameterFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" - }, - "cacheKeyParameters": [ - "method.request.header.Authorization" - ] - }, - "responses": {}, - "parameters": [ - { - "required": true, - "type": "string", - "name": "Authorization", - "in": "header" - } - ] - } - } - }, - "swagger": "2.0" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "NoApiParameterFunctionRole", + "Arn" ] }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiParameterFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "NoApiParameterFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "ApiParameterFunction" + "Ref": "NoApiParameterFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "Api" + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "NoApiParameterFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "ApiDeploymentd779e9df57" - }, - "RestApiId": { - "Ref": "Api" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": false, - "type": "string", + "in": "query", "name": "type", - "in": "query" + "required": false, + "type": "string" }, { - "required": false, - "type": "string", + "in": "path", "name": "id", - "in": "path" + "required": false, + "type": "string" }, { - "required": false, - "type": "string", + "in": "query", "name": "full.type", - "in": "query" + "required": false, + "type": "string" } - ] + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" + } + } } } }, @@ -268,30 +268,30 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "NoApiParameterFunction": { - "Type": "AWS::Lambda::Function", + "ServerlessRestApiDeployment32042a0513": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" + "Description": "RestApi deployment id: 32042a0513cd1c4e5c14794b306c4de10ca5c4af", + "RestApiId": { + "Ref": "ServerlessRestApi" }, - "Role": { - "Fn::GetAtt": [ - "NoApiParameterFunctionRole", - "Arn" - ] + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment32042a0513" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/function_with_resource_refs.json b/tests/translator/output/aws-cn/function_with_resource_refs.json index 89ab2a671c..2a6cf13138 100644 --- a/tests/translator/output/aws-cn/function_with_resource_refs.json +++ b/tests/translator/output/aws-cn/function_with_resource_refs.json @@ -4,193 +4,193 @@ "Value": { "Ref": "MinimalFunctionAliaslive" } - }, - "VersionArn": { + }, + "AliasInSub": { "Value": { - "Ref": "MinimalFunctionVersion640128d35d" + "Fn::Sub": [ + "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", + { + "SomeValue": "World" + } + ] } - }, - "VersionNumber": { + }, + "AliasName": { "Value": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "MinimalFunctionAliaslive", + "Name" ] } - }, - "AliasName": { + }, + "MustNotResolve": { "Value": { "Fn::GetAtt": [ - "MinimalFunctionAliaslive", - "Name" + "FunctionWithoutAlias", + "Alias.Name" ] } - }, + }, "UnResolvedVersion": { "Value": { "Ref": "FunctionWithoutAlias.Version" } - }, - "AliasInSub": { + }, + "VersionArn": { "Value": { - "Fn::Sub": [ - "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", - { - "SomeValue": "World" - } - ] + "Ref": "MinimalFunctionVersion640128d35d" } - }, - "MustNotResolve": { + }, + "VersionNumber": { "Value": { "Fn::GetAtt": [ - "FunctionWithoutAlias", - "Alias.Name" + "MinimalFunctionVersion640128d35d", + "Version" ] } } - }, + }, "Resources": { "FunctionWithoutAlias": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithoutAliasRole", + "FunctionWithoutAliasRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithoutAliasRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithoutAliasRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "MyBucket": { - "Type": "AWS::S3::Bucket", "Properties": { "Name": { "Fn::GetAtt": [ - "MinimalFunctionAliaslive", + "MinimalFunctionAliaslive", "Name" ] } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + }, + "Type": "AWS::S3::Bucket" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_self_managed_kafka.json b/tests/translator/output/aws-cn/function_with_self_managed_kafka.json index 329b61b0a6..827fe97961 100644 --- a/tests/translator/output/aws-cn/function_with_self_managed_kafka.json +++ b/tests/translator/output/aws-cn/function_with_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,48 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SelfManagedKafkaEventSourceConfig": { + "ConsumerGroupId": "consumergroup1" + }, + "SourceAccessConfigurations": [ + { + "Type": "SASL_SCRAM_512_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +76,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -82,43 +117,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "SASL_SCRAM_512_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - }, - "SelfManagedKafkaEventSourceConfig": { - "ConsumerGroupId": "consumergroup1" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_signing_profile.json b/tests/translator/output/aws-cn/function_with_signing_profile.json index d25c7e5266..f3f21f922a 100644 --- a/tests/translator/output/aws-cn/function_with_signing_profile.json +++ b/tests/translator/output/aws-cn/function_with_signing_profile.json @@ -1,36 +1,34 @@ { "Resources": { "FunctionWithSigningProfile": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + "CodeSigningConfigArn": { + "Ref": "MySignedFunctionCodeSigningConfig" + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionWithSigningProfileRole", "Arn" ] }, - "CodeSigningConfigArn": { - "Ref": "MySignedFunctionCodeSigningConfig" - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithSigningProfileRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -43,25 +41,23 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySignedFunctionCodeSigningConfig": { - "Type": "AWS::Lambda::CodeSigningConfig", "Properties": { - "CodeSigningPolicies": { - "UntrustedArtifactOnDeployment": "Enforce" - }, "AllowedPublishers": { "SigningProfileVersionArns": [ { @@ -72,14 +68,18 @@ } ] }, + "CodeSigningPolicies": { + "UntrustedArtifactOnDeployment": "Enforce" + }, "Description": "Code Signing for MySignedLambdaFunction" - } + }, + "Type": "AWS::Lambda::CodeSigningConfig" }, "SigningProfile": { - "Type": "AWS::Signer::SigningProfile", "Properties": { "PlatformId": "AWSLambda-SHA384-ECDSA" - } + }, + "Type": "AWS::Signer::SigningProfile" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/function_with_sns_event_source_all_parameters.json b/tests/translator/output/aws-cn/function_with_sns_event_source_all_parameters.json index 7cf732ff10..4e36842604 100644 --- a/tests/translator/output/aws-cn/function_with_sns_event_source_all_parameters.json +++ b/tests/translator/output/aws-cn/function_with_sns_event_source_all_parameters.json @@ -1,22 +1,47 @@ { "Resources": { + "MyAwesomeFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyAwesomeFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "MyAwesomeFunction", + "Arn" + ] + }, "FilterPolicy": { - "store": [ - "example_corp" + "customer_interests": [ + "rugby", + "football", + "baseball" ], "event": [ { "anything-but": "order_cancelled" } ], - "customer_interests": [ - "rugby", - "football", - "baseball" - ], "price_usd": [ { "numeric": [ @@ -24,44 +49,31 @@ 100 ] } - ] - }, - "Endpoint": { - "Fn::GetAtt": [ - "MyAwesomeFunction", - "Arn" + ], + "store": [ + "example_corp" ] }, "Protocol": "lambda", - "TopicArn": "topicArn", - "Region": "region" - } + "Region": "region", + "TopicArn": "topicArn" + }, + "Type": "AWS::SNS::Subscription" }, "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunction" }, + "Principal": "sns.amazonaws.com", "SourceArn": "topicArn" - } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -74,32 +86,20 @@ ] } } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MyAwesomeFunctionRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/function_with_vpc_permission_for_self_managed_kafka.json b/tests/translator/output/aws-cn/function_with_vpc_permission_for_self_managed_kafka.json index ca6ec60137..72c9e49829 100644 --- a/tests/translator/output/aws-cn/function_with_vpc_permission_for_self_managed_kafka.json +++ b/tests/translator/output/aws-cn/function_with_vpc_permission_for_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,41 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SourceAccessConfigurations": [ + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +69,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -75,36 +103,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/global_handle_path_level_parameter.json b/tests/translator/output/aws-cn/global_handle_path_level_parameter.json index 51b5040b7f..c529037537 100644 --- a/tests/translator/output/aws-cn/global_handle_path_level_parameter.json +++ b/tests/translator/output/aws-cn/global_handle_path_level_parameter.json @@ -1,102 +1,47 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "parameters": [ - { - "required": true, - "type": "string", - "description": "Application domain", - "name": "domain", - "in": "path" - } - ], "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "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" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } + } + }, + "parameters": [ + { + "description": "Application domain", + "in": "path", + "name": "domain", + "required": true, + "type": "string" + } + ] } }, - "swagger": 2.0, "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -110,7 +55,8 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": 2.0 }, "EndpointConfiguration": { "Types": [ @@ -121,80 +67,112 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymente1212668e0" - } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ServerlessRestApiDeploymente1212668e0": { - "Type": "AWS::ApiGateway::Deployment", + "ExplicitApiDeployment9a254aa466": { "Properties": { + "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", "RestApiId": { - "Ref": "ServerlessRestApi" + "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: e1212668e096994ab32167666f5a877bd6ac5fad", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment9a254aa466" + }, "RestApiId": { "Ref": "ExplicitApi" }, "StageName": "SomeStage", - "CacheClusterSize": "1.6", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment9a254aa466" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", + "ImplicitApiFunctionRole": { "Properties": { - "UsernameAttributes": [ - "email" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "UserPoolName": "UserPoolName", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { "Policies": { "PasswordPolicy": { "MinimumLength": 8 @@ -203,57 +181,50 @@ "Schema": [ { "AttributeDataType": "String", - "Required": false, - "Name": "email" + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, - "ExplicitApiDeployment9a254aa466": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", - "StageName": "Stage" - } + }, + "Type": "AWS::Cognito::UserPool" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -267,7 +238,8 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -278,7 +250,35 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymente1212668e0": { + "Properties": { + "Description": "RestApi deployment id: e1212668e096994ab32167666f5a877bd6ac5fad", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymente1212668e0" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/globals_for_api.json b/tests/translator/output/aws-cn/globals_for_api.json index 27c4118f0e..ee86381d30 100644 --- a/tests/translator/output/aws-cn/globals_for_api.json +++ b/tests/translator/output/aws-cn/globals_for_api.json @@ -1,291 +1,291 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "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": {}, "security": [ { "MyCognitoAuth": [] - }, + }, { "api_key": [] } - ], - "responses": {} + ], + "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" + } + } } } - }, - "swagger": 2.0, + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": 2.0 + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment43e01e673d": { "Properties": { + "Description": "RestApi deployment id: 43e01e673d7acbd09e4c38ff78dd6ddaf2ed1d55", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentf6c326a165" - } - } - }, + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment43e01e673d" + }, "RestApiId": { "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", + }, + "StageName": "SomeStage", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment43e01e673d" } - } - }, - "ServerlessRestApiDeploymentf6c326a165": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: f6c326a1656cc9fbb0106cc645598d88575554eb", - "StageName": "Stage" - } - }, - "ExplicitApiDeployment43e01e673d": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 43e01e673d7acbd09e4c38ff78dd6ddaf2ed1d55", - "StageName": "Stage" - } - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 } - }, + }, "Schema": [ { - "AttributeDataType": "String", - "Required": false, - "Name": "email" + "AttributeDataType": "String", + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, + }, + "Type": "AWS::Cognito::UserPool" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "MyCognitoAuth": [] - }, + }, { "api_key": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentf6c326a165": { + "Properties": { + "Description": "RestApi deployment id: f6c326a1656cc9fbb0106cc645598d88575554eb", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentf6c326a165" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/globals_for_function.json b/tests/translator/output/aws-cn/globals_for_function.json index 01050a770d..0b58482e8b 100644 --- a/tests/translator/output/aws-cn/globals_for_function.json +++ b/tests/translator/output/aws-cn/globals_for_function.json @@ -1,251 +1,255 @@ { "Resources": { - "FunctionWithOverridesRole": { - "Type": "AWS::IAM::Role", + "FunctionWithOverrides": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + "Architectures": [ + "x86_64" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Environment": { + "Variables": { + "Var1": "value1", + "Var2": "value2", + "Var3": "value3" + } + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "index.handler", + "Layers": [ { - "Value": "newvalue1", - "Key": "newtag1" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" }, { - "Value": "value1", - "Key": "tag1" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" } ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "MemorySize": 512, + "ReservedConcurrentExecutions": 100, + "Role": { + "Fn::GetAtt": [ + "FunctionWithOverridesRole", + "Arn" ] - } - } - }, - "FunctionWithOverrides": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" + "Key": "newtag1", + "Value": "newvalue1" + }, + { + "Key": "tag1", + "Value": "value1" } - ], + ], + "Timeout": 100, "TracingConfig": { "Mode": "PassThrough" - }, - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + }, "VpcConfig": { - "SubnetIds": [ - "sub-id-2" - ], "SecurityGroupIds": [ - "sg-edcd9784", + "sg-edcd9784", "sg-123" + ], + "SubnetIds": [ + "sub-id-2" ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "newvalue1", - "Key": "newtag1" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "ReservedConcurrentExecutions": 100, - "Architectures": ["x86_64"], - "EphemeralStorage": { - "Size": 1024 + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithOverridesAliasprod": { + "Properties": { + "FunctionName": { + "Ref": "FunctionWithOverrides" }, - "MemorySize": 512, - "Environment": { - "Variables": { - "Var1": "value1", - "Var3": "value3", - "Var2": "value2" - } - }, - "Handler": "index.handler", - "Role": { + "FunctionVersion": { "Fn::GetAtt": [ - "FunctionWithOverridesRole", - "Arn" + "FunctionWithOverridesVersion096ed3b52b", + "Version" ] - }, - "Timeout": 100, - "Runtime": "nodejs12.x" - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Name": "prod" + }, + "Type": "AWS::Lambda::Alias" + }, + "FunctionWithOverridesRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithOverridesAliasprod": { - "Type": "AWS::Lambda::Alias", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "newtag1", + "Value": "newvalue1" + }, + { + "Key": "tag1", + "Value": "value1" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithOverridesVersion096ed3b52b": { + "DeletionPolicy": "Retain", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionWithOverridesVersion096ed3b52b", - "Version" - ] - }, "FunctionName": { "Ref": "FunctionWithOverrides" - }, - "Name": "prod" - } - }, + } + }, + "Type": "AWS::Lambda::Version" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Layers": [ - { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" - } - ], - "TracingConfig": { - "Mode": "Active" - }, + "Architectures": [ + "x86_64" + ], "Code": { - "S3Bucket": "global-bucket", + "S3Bucket": "global-bucket", "S3Key": "global.zip" - }, - "VpcConfig": { - "SubnetIds": [ - "sub-id-2" - ], - "SecurityGroupIds": [ - "sg-edcd9784" - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "ReservedConcurrentExecutions": 50, - "Architectures": ["x86_64"], - "EphemeralStorage": { - "Size": 1024 }, - "MemorySize": 1024, "Environment": { "Variables": { - "Var1": "value1", + "Var1": "value1", "Var2": "value2" } - }, - "Handler": "hello.handler", + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "hello.handler", + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + } + ], + "MemorySize": 1024, + "ReservedConcurrentExecutions": 50, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Timeout": 30, - "Runtime": "python2.7" - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "tag1", + "Value": "value1" + } + ], + "Timeout": 30, + "TracingConfig": { + "Mode": "Active" + }, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "sub-id-2" + ] + } + }, + "Type": "AWS::Lambda::Function" + }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ "MinimalFunctionVersion0a06fc8fb1", "Version" ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, + }, "Name": "live" - } - }, - "FunctionWithOverridesVersion096ed3b52b": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { "Properties": { - "FunctionName": { - "Ref": "FunctionWithOverrides" - } - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "tag1", + "Value": "value1" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion0a06fc8fb1": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/globals_for_simpletable.json b/tests/translator/output/aws-cn/globals_for_simpletable.json index 313fd286c3..d937d9ef86 100644 --- a/tests/translator/output/aws-cn/globals_for_simpletable.json +++ b/tests/translator/output/aws-cn/globals_for_simpletable.json @@ -1,25 +1,25 @@ { - "Resources": { - "MinimalTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "SSESpecification": { - "SSEEnabled": true - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] + "Resources": { + "MinimalTable": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "SSESpecification": { + "SSEEnabled": true } - } + }, + "Type": "AWS::DynamoDB::Table" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/http_api_custom_iam_auth.json b/tests/translator/output/aws-cn/http_api_custom_iam_auth.json index 295aab3d87..e93d03856b 100644 --- a/tests/translator/output/aws-cn/http_api_custom_iam_auth.json +++ b/tests/translator/output/aws-cn/http_api_custom_iam_auth.json @@ -2,22 +2,42 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionHelloAWSIAMAuthPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "MyApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/hello-aws-iam-auth" ] } @@ -29,9 +49,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -39,7 +65,12 @@ "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -53,7 +84,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -61,13 +95,22 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/hello-aws-iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -80,8 +123,14 @@ } }, "tags": [ - { "name": "Tag1", "x-amazon-apigateway-tag-value": "value1" }, - { "name": "Tag2", "x-amazon-apigateway-tag-value": "value2" }, + { + "name": "Tag1", + "x-amazon-apigateway-tag-value": "value1" + }, + { + "name": "Tag2", + "x-amazon-apigateway-tag-value": "value2" + }, { "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" @@ -93,7 +142,9 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", "Tags": { @@ -106,11 +157,24 @@ }, "MyAuthFn": { "Properties": { - "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, "Handler": "index.handler", - "Role": { "Fn::GetAtt": ["Arn", "MyAuthFnRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "MyAuthFnRole" + ] + }, "Runtime": "nodejs12.x", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, @@ -119,9 +183,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -129,7 +199,12 @@ "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" } diff --git a/tests/translator/output/aws-cn/http_api_def_uri.json b/tests/translator/output/aws-cn/http_api_def_uri.json index f285640fc4..038b1a2baf 100644 --- a/tests/translator/output/aws-cn/http_api_def_uri.json +++ b/tests/translator/output/aws-cn/http_api_def_uri.json @@ -1,151 +1,151 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionApi2Permission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", - "__ApiId__": "MyApi" + "__ApiId__": { + "Ref": "MyApi2" + }, + "__Stage__": "*" } ] } - } - }, - "MyApiStage": { - "Type": "AWS::ApiGatewayV2::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionApiPermission": { "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "DefaultRouteSettings": { - "ThrottlingBurstLimit": 50, - "ThrottlingRateLimit": 100.0 + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" }, - "StageName": { - "Fn::Join": [ - "", - [ - "Stage", - "Name" - ] + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": "MyApi", + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "MyApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "bucket", + "Key": "key" + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2": { + "Properties": { + "BodyS3Location": { + "Bucket": "bucket", + "Key": "key", + "Version": "version" + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi2" - }, + }, "AutoDeploy": true, "DefaultRouteSettings": { - "ThrottlingRateLimit": 100 + "ThrottlingRateLimit": 100 }, "StageName": "$default" - } - }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "BodyS3Location": { - "Version": "version", - "Bucket": "bucket", - "Key": "key" - } - } - }, - "FunctionApi2Permission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApiStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi2" - } - } + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingBurstLimit": 50, + "ThrottlingRateLimit": 100.0 + }, + "StageName": { + "Fn::Join": [ + "", + [ + "Stage", + "Name" + ] ] } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "BodyS3Location": { - "Bucket": "bucket", - "Key": "key" - } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-cn/http_api_description.json b/tests/translator/output/aws-cn/http_api_description.json index e5b49fcb3e..47b2bdf147 100644 --- a/tests/translator/output/aws-cn/http_api_description.json +++ b/tests/translator/output/aws-cn/http_api_description.json @@ -1,123 +1,123 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", - "__ApiId__": "HttpApi" + "__ApiId__": "HttpApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "HttpApi" - }, - "Tags": { - "httpapi:createdBy": "SAM" - }, - "StageName": "$default" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "HttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "info": { + "description": "my description" + }, "openapi": "3.0.1", "paths": { - "/foo": {}, "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {} + } } - } + }, + "/foo": {} }, "tags": [ { "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ], - "info": { - "description": "my description" - } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "HttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "HttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/http_api_existing_openapi.json b/tests/translator/output/aws-cn/http_api_existing_openapi.json index 606deddcb9..4a5b51a396 100644 --- a/tests/translator/output/aws-cn/http_api_existing_openapi.json +++ b/tests/translator/output/aws-cn/http_api_existing_openapi.json @@ -1,276 +1,276 @@ { "Parameters": { "Timeout": { - "Default": 15000, + "Default": 15000, "Type": "Number" } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "OpenIdAuth": { + "type": "openIdConnect", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "openIdConnectUrl": "https://www.example.com/v1/connect", + "type": "jwt" + } + }, + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get/{something}/with/{params}": { - "get": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope1", + "scope2" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "timeoutInMillis": { + "Ref": "Timeout" + }, + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {}, - "parameters": [ - { - "required": true, - "name": "something", - "in": "path" - }, - { - "required": true, - "name": "params", - "in": "path" } - ] + } } - }, + }, "/basic": { "post": { - "x-amazon-apigateway-integration": { - "payloadFormatVersion": "1.0", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "httpMethod": "POST", - "timeoutInMillis": 10000 - }, + "responses": {}, "security": [ { "OpenIdAuth": [ "scope3" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "timeoutInMillis": 10000, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } } - }, - "/integration": { - "post": { + }, + "/get/{something}/with/{params}": { + "get": { + "parameters": [ + { + "in": "path", + "name": "something", + "required": true + }, + { + "in": "path", + "name": "params", + "required": true + } + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope1", - "scope2" - ] } - ], - "responses": {} + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/integration": { + "post": { + "responses": {}, "security": [ { "OpenIdAuth": [ - "scope1", + "scope1", "scope2" ] } - ], - "isDefaultRoute": true, + ], "x-amazon-apigateway-integration": { - "payloadFormatVersion": "1.0", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "httpMethod": "POST", - "timeoutInMillis": { - "Ref": "Timeout" } - }, - "responses": {} + } } - }, + }, "/oauth2": { "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } } - }, + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ], "x-amazon-apigateway-cors": { - "allowMethods": [ - "GET" - ], "allowHeaders": [ "x-apigateway-header" - ], + ], + "allowMethods": [ + "GET" + ], "allowOrigins": [ - "https://global.com", + "https://global.com", "https://local.com" - ], + ], "maxAge": 6000 - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - }, - "OpenIdAuth": { - "type": "openIdConnect", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "openIdConnectUrl": "https://www.example.com/v1/connect" - } - } - } } } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/http_api_existing_openapi_conditions.json b/tests/translator/output/aws-cn/http_api_existing_openapi_conditions.json index c674491ca4..6ee3e57ce5 100644 --- a/tests/translator/output/aws-cn/http_api_existing_openapi_conditions.json +++ b/tests/translator/output/aws-cn/http_api_existing_openapi_conditions.json @@ -2,295 +2,295 @@ "Conditions": { "condition": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "condition" - }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM", - "Tag1": "value1", - "Tag2": "value2" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "condition", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "condition" - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "condition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "condition" - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Condition": "condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "OAuth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + }, + "OpenIdAuth": { + "type": "openIdConnect", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "openIdConnectUrl": "https://www.example.com/v1/connect", + "type": "jwt" + } + }, + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope3" - ] - } - ], - "responses": {} - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OAuth2": [ - "basic" - ] - } - ], - "responses": {} - } - }, - "/integration": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope1", - "scope2" - ] - } - ], - "responses": {} - } - }, "$default": { "x-amazon-apigateway-any-method": { "Fn::If": [ - "condition", + "condition", { + "isDefaultRoute": true, + "responses": {}, "security": [ { "OpenIdAuth": [ - "scope1", + "scope1", "scope2" ] } - ], - "isDefaultRoute": true, + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "condition", + "condition", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, - "/oauth2": { + }, + "/basic": { + "get": { + "responses": {}, + "security": [ + { + "OAuth2": [ + "basic" + ] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } + }, "post": { + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope3" + ] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } + } + }, + "/integration": { + "post": { + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope1", + "scope2" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, + } + } + } + }, + "/oauth2": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - } - }, - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - }, - "OAuth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } } - }, - "OpenIdAuth": { - "type": "openIdConnect", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "openIdConnectUrl": "https://www.example.com/v1/connect" - } } } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" }, { - "name": "Tag1", - "x-amazon-apigateway-tag-value": "value1", - "description": "this tag exists, but doesn't have an amazon extension value" - }, + "description": "this tag exists, but doesn't have an amazon extension value", + "name": "Tag1", + "x-amazon-apigateway-tag-value": "value1" + }, { - "name": "Tag2", + "name": "Tag2", "x-amazon-apigateway-tag-value": "value2" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "Tag1": "value1", + "Tag2": "value2", + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-cn/http_api_explicit_stage.json b/tests/translator/output/aws-cn/http_api_explicit_stage.json index eb33d241d4..4cf02a5c45 100644 --- a/tests/translator/output/aws-cn/http_api_explicit_stage.json +++ b/tests/translator/output/aws-cn/http_api_explicit_stage.json @@ -1,160 +1,160 @@ { "Parameters": { "CorsParam": { - "Default": true, + "Default": true, "Type": "String" }, "PayloadFormatVersion": { - "Default": "1.0", - "Type": "String" + "Default": "1.0", + "Type": "String" } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "StageVariables": { - "VarName": "VarValue" - }, - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod", - "AccessLogSettings": { - "DestinationArn": "arn:aws:logs:us-east-1:123456789012:log-group:LogGroupName", - "Format": "$context.requestId" - }, - "RouteSettings": { - "$default": { - "ThrottlingRateLimit": 0.7, - "DataTraceEnabled": true, - "ThrottlingBurstLimit": 300, - "LoggingLevel": "INFO" - } - }, - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { - "FailOnWarnings": true, "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, + "httpMethod": "POST", "payloadFormatVersion": { "Ref": "PayloadFormatVersion" + }, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {} + } } } - }, - "x-amazon-apigateway-cors": { - "allowOrigins": [ - "*" - ] - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ] + ], + "x-amazon-apigateway-cors": { + "allowOrigins": [ + "*" + ] + } + }, + "FailOnWarnings": true + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "AccessLogSettings": { + "DestinationArn": "arn:aws:logs:us-east-1:123456789012:log-group:LogGroupName", + "Format": "$context.requestId" + }, + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "RouteSettings": { + "$default": { + "DataTraceEnabled": true, + "LoggingLevel": "INFO", + "ThrottlingBurstLimit": 300, + "ThrottlingRateLimit": 0.7 + } + }, + "StageName": "Prod", + "StageVariables": { + "VarName": "VarValue" + }, + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled.json b/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled.json index 4b0504085d..85cce91bf2 100644 --- a/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled.json +++ b/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled.json @@ -2,22 +2,42 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionImplicitApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "ServerlessHttpApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" ] } @@ -27,11 +47,18 @@ "HttpApiFunctionImplicitApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "ServerlessHttpApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" ] } @@ -43,9 +70,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -53,7 +86,12 @@ "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -70,7 +108,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { @@ -89,7 +132,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -113,10 +160,14 @@ }, "ServerlessHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "ServerlessHttpApi" }, + "ApiId": { + "Ref": "ServerlessHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json b/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json index ceea480e89..e9e8279554 100644 --- a/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json +++ b/tests/translator/output/aws-cn/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json @@ -10,7 +10,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -18,7 +21,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": {}, "tags": [ @@ -33,10 +41,14 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-cn/http_api_lambda_auth.json b/tests/translator/output/aws-cn/http_api_lambda_auth.json index 9f40ee94f2..56bcf5fdab 100644 --- a/tests/translator/output/aws-cn/http_api_lambda_auth.json +++ b/tests/translator/output/aws-cn/http_api_lambda_auth.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,149 +71,96 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerPayloadFormatVersion": 1.0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "request" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/basic": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerPayloadFormatVersion": 1.0 } } } @@ -234,22 +180,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "AutoDeploy": true - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/http_api_lambda_auth_full.json b/tests/translator/output/aws-cn/http_api_lambda_auth_full.json index 7fe416f92b..71532999af 100644 --- a/tests/translator/output/aws-cn/http_api_lambda_auth_full.json +++ b/tests/translator/output/aws-cn/http_api_lambda_auth_full.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,163 +71,110 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 2.0, + "authorizerResultTtlInSeconds": 60, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "enableSimpleResponses": true, + "identitySource": [ + "$context.contextVar", + "$request.header.Authorization", + "$request.querystring.petId", + "$stageVariables.stageVar" + ], + "type": "request" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/basic": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "identitySource": [ - "$context.contextVar", - "$request.header.Authorization", - "$request.querystring.petId", - "$stageVariables.stageVar" - ], - "authorizerResultTtlInSeconds": 60, - "authorizerPayloadFormatVersion": 2.0, - "enableSimpleResponses": true } } } @@ -248,22 +194,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "AutoDeploy": true - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled.json b/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled.json index 6cf579d137..388932be9f 100644 --- a/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled.json +++ b/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled.json @@ -2,23 +2,40 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionMyDefaultIamAuthHttpApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" @@ -30,12 +47,16 @@ "HttpApiFunctionMyDefaultIamAuthHttpApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" @@ -47,12 +68,16 @@ "HttpApiFunctionMyDefaultIamAuthHttpApiNoAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-auth" @@ -64,12 +89,16 @@ "HttpApiFunctionMyIamAuthEnabledHttpApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyIamAuthEnabledHttpApi" }, + "__ApiId__": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" @@ -81,12 +110,16 @@ "HttpApiFunctionMyIamAuthEnabledHttpApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyIamAuthEnabledHttpApi" }, + "__ApiId__": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" @@ -100,9 +133,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -110,7 +149,12 @@ "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -127,13 +171,22 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -147,7 +200,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -161,7 +218,11 @@ "/no-auth": { "get": { "responses": {}, - "security": [{ "NONE": [] }], + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -185,10 +246,14 @@ }, "MyDefaultIamAuthHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyDefaultIamAuthHttpApi" }, + "ApiId": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" }, @@ -205,7 +270,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { @@ -224,7 +294,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -248,10 +322,14 @@ }, "MyIamAuthEnabledHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyIamAuthEnabledHttpApi" }, + "ApiId": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json b/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json index ceea480e89..e9e8279554 100644 --- a/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json +++ b/tests/translator/output/aws-cn/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json @@ -10,7 +10,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -18,7 +21,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": {}, "tags": [ @@ -33,10 +41,14 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-cn/http_api_multiple_authorizers.json b/tests/translator/output/aws-cn/http_api_multiple_authorizers.json index a42dc5f8a6..5a78fa1d17 100644 --- a/tests/translator/output/aws-cn/http_api_multiple_authorizers.json +++ b/tests/translator/output/aws-cn/http_api_multiple_authorizers.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -9,7 +8,10 @@ }, "Handler": "index.restapi", "Role": { - "Fn::GetAtt": ["HttpApiFunctionRole", "Arn"] + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] }, "Runtime": "python3.7", "Tags": [ @@ -18,22 +20,26 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -44,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -65,190 +71,152 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": ["MyAuthFnRole", "Arn"] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": ["sts:AssumeRole"], - "Effect": "Allow", - "Principal": { - "Service": ["lambda.amazonaws.com"] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + }, + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerPayloadFormatVersion": 1.0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "request" + } + }, + "MyOauth2Authorizer": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.header.Authorization", + "jwtConfiguration": { + "audience": [ + "audience1", + "audience2" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/hello": { - "get": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/hello": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyOauth2Authorizer": ["scope"] + "LambdaAuth": [] } - ] - }, - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { - "LambdaAuth": [] + "MyOauth2Authorizer": [ + "scope" + ] } - ] - } - }, - "/hello-aws-iam-auth": { - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/hello-aws-iam-auth": { + "get": { "responses": {}, "security": [ { "AWS_IAM": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "AWS_IAM": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "awsSigv4" - }, - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": ["MyAuthFn", "Arn"] - } - } - ] - }, - "authorizerPayloadFormatVersion": 1.0 - } - }, - "MyOauth2Authorizer": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "jwtConfiguration": { - "audience": ["audience1", "audience2"], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "identitySource": "$request.header.Authorization", - "type": "jwt" } } } @@ -268,22 +236,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "AutoDeploy": true - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/http_api_with_cors.json b/tests/translator/output/aws-cn/http_api_with_cors.json index ccf90e087d..d4bff8aa03 100644 --- a/tests/translator/output/aws-cn/http_api_with_cors.json +++ b/tests/translator/output/aws-cn/http_api_with_cors.json @@ -2,214 +2,138 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} - } - } - }, - "x-amazon-apigateway-cors": { - "Fn::If": [ - "C1", - { - "allowHeaders": [ - "x-apigateway-header" - ], - "allowMethods": [ - "GET" - ], - "allowOrigins": [ - "https://foo.com" - ], - "exposeHeaders": [ - "x-amzn-header" - ] - }, - "AWS::NoValue" - ] - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n console.log(\"Hello from MyAuthFunction\")\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionImplicitApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ], "x-amazon-apigateway-cors": { "Fn::If": [ "C1", @@ -229,16 +153,92 @@ }, "AWS::NoValue" ] - }, - "openapi": "3.0.1", + } + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "ServerlessHttpApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } + } + } + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ] + ], + "x-amazon-apigateway-cors": { + "Fn::If": [ + "C1", + { + "allowHeaders": [ + "x-apigateway-header" + ], + "allowMethods": [ + "GET" + ], + "allowOrigins": [ + "https://foo.com" + ], + "exposeHeaders": [ + "x-amzn-header" + ] + }, + "AWS::NoValue" + ] + } + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/http_api_with_custom_domain_route53_multiple.json b/tests/translator/output/aws-cn/http_api_with_custom_domain_route53_multiple.json index 1be40930c5..4027452a35 100644 --- a/tests/translator/output/aws-cn/http_api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/aws-cn/http_api_with_custom_domain_route53_multiple.json @@ -1,255 +1,255 @@ { - "Resources": { - "MyApi1": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, - "ApiGatewayDomainNameV25fe29fe649": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.one.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApi1ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi1" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV25fe29fe649" - }, - "Stage": { - "Ref": "MyApi1ApiGatewayDefaultStage" - } - } - }, - "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "abc123456", - "RecordSets": [ - { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV23fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV23fd2dbd8f8", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.three.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV241bfc7f9c4", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV241bfc7f9c4", - "RegionalDomainName" - ] - } - } - } - ] + "Resources": { + "ApiGatewayDomainNameV23fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "ApiGatewayDomainNameV241bfc7f9c4": { + "Properties": { + "DomainName": "admin.three.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "ApiGatewayDomainNameV25fe29fe649": { + "Properties": { + "DomainName": "admin.one.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi1": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi1ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi1" }, - "MyApi1ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi1" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi1ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi1" }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV25fe29fe649" }, - "ApiGatewayDomainNameV23fd2dbd8f8": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.two.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } + "Stage": { + "Ref": "MyApi1ApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApi2": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" }, - "MyApi2ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV23fd2dbd8f8" - }, - "Stage": { - "Ref": "MyApi2ApiGatewayDefaultStage" - } - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi2ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" }, - "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV23fd2dbd8f8" }, - "MyApi3": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } + "Stage": { + "Ref": "MyApi2ApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApi3": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi3ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi3" }, - "ApiGatewayDomainNameV241bfc7f9c4": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.three.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi3ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi3" }, - "MyApi3ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi3" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV241bfc7f9c4" - }, - "Stage": { - "Ref": "MyApi3ApiGatewayDefaultStage" - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV241bfc7f9c4" }, - "MyApi3ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi3" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "Stage": { + "Ref": "MyApi3ApiGatewayDefaultStage" } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "RecordSetGroup370194ff6e": { + "Properties": { + "HostedZoneId": "abc123456", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV23fd2dbd8f8", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV23fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV241bfc7f9c4", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV241bfc7f9c4", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.three.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/http_api_with_null_path.json b/tests/translator/output/aws-cn/http_api_with_null_path.json index dc55dbed73..09f887c3fb 100644 --- a/tests/translator/output/aws-cn/http_api_with_null_path.json +++ b/tests/translator/output/aws-cn/http_api_with_null_path.json @@ -1,122 +1,122 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", - "Resources": { - "EXAMPLEPARTIALLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "EXAMPLEPARTIALLambdaRole", - "Arn" - ] - }, - "Runtime": "python3.9", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "EXAMPLEPARTIALLambdaRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", + "Resources": { + "EXAMPLEPARTIALGateway": { + "Properties": { + "Body": { + "openapi": "3.0.1", + "paths": { + "/my/route": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EXAMPLEPARTIALLambda.Arn}/invocations" + } } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "EXAMPLEPARTIALLambdaPostRequestPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "EXAMPLEPARTIALLambda" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/my/route", - { - "__ApiId__": { - "Ref": "EXAMPLEPARTIALGateway" - }, - "__Stage__": "*" - } - ] + "Type": "AWS::ApiGatewayV2::Api" + }, + "EXAMPLEPARTIALGatewayApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "EXAMPLEPARTIALGateway" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "EXAMPLEPARTIALLambda": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "EXAMPLEPARTIALLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.9", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "EXAMPLEPARTIALLambdaPostRequestPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "EXAMPLEPARTIALLambda" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/my/route", + { + "__ApiId__": { + "Ref": "EXAMPLEPARTIALGateway" + }, + "__Stage__": "*" + } + ] } }, - "EXAMPLEPARTIALGateway": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "openapi": "3.0.1", - "paths": { - "/my/route": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EXAMPLEPARTIALLambda.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Type": "AWS::Lambda::Permission" + }, + "EXAMPLEPARTIALLambdaRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "EXAMPLEPARTIALGatewayApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "EXAMPLEPARTIALGateway" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } - } + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/implicit_and_explicit_api_with_conditions.json b/tests/translator/output/aws-cn/implicit_and_explicit_api_with_conditions.json index 4ebfafc91b..edc7c70ded 100644 --- a/tests/translator/output/aws-cn/implicit_and_explicit_api_with_conditions.json +++ b/tests/translator/output/aws-cn/implicit_and_explicit_api_with_conditions.json @@ -11,341 +11,68 @@ } ] }, - "explicithello2condition": { + "explicithello1condition": { "Fn::Equals": [ true, false ] }, - "implicithello1condition": { + "explicithello2condition": { "Fn::Equals": [ true, false ] }, - "implicithello2condition": { + "implicithello1condition": { "Fn::Equals": [ true, false ] }, - "explicithello1condition": { + "implicithello2condition": { "Fn::Equals": [ true, false ] } }, + "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", "Resources": { - "explicithello2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "explicithello2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "explicithello2condition" - }, - "implicithello2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "implicithello2condition" - }, - "explicithello1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "explicithello1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "explicithello1condition" - }, - "ServerlessRestApiDeploymentafcab1755e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: afcab1755e409da73b339b6deff571f5b8a821da", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "explicitapiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "explicitapiDeploymentc5102c0776" - }, - "RestApiId": { - "Ref": "explicitapi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentafcab1755e" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "explicithello2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "explicithello2condition" - }, - "explicithello1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "explicithello1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "explicitapi" - } - } - ] - } - }, - "Condition": "explicithello1condition" - }, - "implicithello2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "implicithello2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "implicithello2condition" - }, - "implicithello1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "implicithello1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "implicithello1condition" - }, - "explicitapiDeploymentc5102c0776": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "explicitapi" - }, - "Description": "RestApi deployment id: c5102c077632f46b21ecf1230d4056848be72538", - "StageName": "Stage" - } - }, - "implicithello1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "implicithello1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "implicithello1condition" - }, - "explicithello2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "explicithello2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "explicitapi" - } - } - ] - } - }, - "Condition": "explicithello2condition" - }, - "explicitapi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/explicit/hello2": { + "/implicit/hello1": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { "get": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello2.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -358,30 +85,30 @@ } ] }, - "/explicit/hello1": { + "/implicit/hello2": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { "get": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello1.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -405,96 +132,67 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "implicithello2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ServerlessRestApiDeploymentafcab1755e": { + "Condition": "ServerlessRestApiCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "implicithello2" + "Description": "RestApi deployment id: afcab1755e409da73b339b6deff571f5b8a821da", + "RestApiId": { + "Ref": "ServerlessRestApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } + "StageName": "Stage" }, - "Condition": "implicithello2condition" + "Type": "AWS::ApiGateway::Deployment" }, - "explicithello1Role": { - "Type": "AWS::IAM::Role", + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentafcab1755e" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" }, - "Condition": "explicithello1condition" + "Type": "AWS::ApiGateway::Stage" }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "explicitapi": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/implicit/hello1": { + "/explicit/hello1": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { "get": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello1.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -507,30 +205,30 @@ } ] }, - "/implicit/hello2": { + "/explicit/hello2": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { "get": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello2.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -555,22 +253,237 @@ "endpointConfigurationTypes": "REGIONAL" } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::ApiGateway::RestApi" }, - "implicithello1Role": { - "Type": "AWS::IAM::Role", + "explicitapiDeploymentc5102c0776": { + "Properties": { + "Description": "RestApi deployment id: c5102c077632f46b21ecf1230d4056848be72538", + "RestApiId": { + "Ref": "explicitapi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "explicitapiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "explicitapiDeploymentc5102c0776" + }, + "RestApiId": { + "Ref": "explicitapi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "explicithello1": { + "Condition": "explicithello1condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "explicithello1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "explicithello1ApiEventPermissionProd": { + "Condition": "explicithello1condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "explicithello1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello1", + { + "__ApiId__": { + "Ref": "explicitapi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "explicithello1Role": { + "Condition": "explicithello1condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "explicithello2": { + "Condition": "explicithello2condition", "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "explicithello2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "explicithello2ApiEventPermissionProd": { + "Condition": "explicithello2condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "explicithello2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello2", + { + "__ApiId__": { + "Ref": "explicitapi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "explicithello2Role": { + "Condition": "explicithello2condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "implicithello1": { + "Condition": "implicithello1condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "implicithello1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "implicithello1ApiEventPermissionProd": { + "Condition": "implicithello1condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "implicithello1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello1", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "implicithello1Role": { + "Condition": "implicithello1condition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -583,11 +496,98 @@ ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "implicithello2": { + "Condition": "implicithello2condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "implicithello2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "implicithello2ApiEventPermissionProd": { + "Condition": "implicithello2condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "implicithello2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello2", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } }, - "Condition": "implicithello1condition" + "Type": "AWS::Lambda::Permission" + }, + "implicithello2Role": { + "Condition": "implicithello2condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "A template to test for API condition handling with a mix of explicit and implicit api events." + } } diff --git a/tests/translator/output/aws-cn/implicit_api.json b/tests/translator/output/aws-cn/implicit_api.json index 9131460778..79f84eaea0 100644 --- a/tests/translator/output/aws-cn/implicit_api.json +++ b/tests/translator/output/aws-cn/implicit_api.json @@ -1,290 +1,290 @@ { "Resources": { - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RestApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "RestApiFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "RestApiFunctionCompleteItemPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "GetHtmlFunction" - }, + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentb5184bf2cc" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "RestApiFunctionGetListPermissionProd": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeploymentb5184bf2cc": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: b5184bf2cccc18d4a1efae523c2c88fd5282c8a3", - "StageName": "Stage" - } - }, - "RestApiFunctionGetListPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/{proxy+}": { - "x-amazon-apigateway-any-method": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/complete": { - "post": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "RestApiFunctionCompleteItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentb5184bf2cc": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: b5184bf2cccc18d4a1efae523c2c88fd5282c8a3", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentb5184bf2cc" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/implicit_api_deletion_policy_precedence.json b/tests/translator/output/aws-cn/implicit_api_deletion_policy_precedence.json index 33a3bb1237..06438b3bd3 100644 --- a/tests/translator/output/aws-cn/implicit_api_deletion_policy_precedence.json +++ b/tests/translator/output/aws-cn/implicit_api_deletion_policy_precedence.json @@ -1,18 +1,16 @@ { "Resources": { - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", + "GetHtmlFunction": { + "DeletionPolicy": "Retain", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, - "Handler": "index.restapi", + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "GetHtmlFunctionRole", "Arn" ] }, @@ -23,15 +21,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function", + "UpdateReplacePolicy": "Retain" }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", + "GetHtmlFunctionGetHtmlPermissionProd": { + "DeletionPolicy": "Retain", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/{proxy++}", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission", + "UpdateReplacePolicy": "Retain" + }, + "GetHtmlFunctionRole": { + "DeletionPolicy": "Retain", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -44,11 +64,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" ], "Tags": [ { @@ -56,12 +77,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role", + "UpdateReplacePolicy": "Retain" + }, + "RestApiFunction": { + "DeletionPolicy": "Delete", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function", + "UpdateReplacePolicy": "Retain" }, "RestApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -79,40 +125,14 @@ } ] } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission", + "UpdateReplacePolicy": "Retain" }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", + "RestApiFunctionRole": { + "DeletionPolicy": "Delete", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -125,11 +145,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" ], "Tags": [ { @@ -137,97 +158,74 @@ "Value": "SAM" } ] - } - }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "GetHtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/{proxy++}", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/{proxy+}": { + "/{proxy++}": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/{proxy++}": { + "/{proxy+}": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ - "REGIONAL" - ] + "REGIONAL" + ] }, "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApiDeployment1ec0d29ab5": { - "Type": "AWS::ApiGateway::Deployment", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "Description": "RestApi deployment id: 1ec0d29ab5c55018bb989df31615c170b707ae21", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment1ec0d29ab5" @@ -236,7 +234,9 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Retain" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/implicit_api_with_auth_and_conditions_max.json b/tests/translator/output/aws-cn/implicit_api_with_auth_and_conditions_max.json index c0bad5fb17..56b64ef620 100644 --- a/tests/translator/output/aws-cn/implicit_api_with_auth_and_conditions_max.json +++ b/tests/translator/output/aws-cn/implicit_api_with_auth_and_conditions_max.json @@ -1,34 +1,18 @@ { "Conditions": { - "ServerlessRestApiCondition": { - "Fn::Or": [ - { - "Condition": "FunctionCondition" - }, - { - "Condition": "FunctionCondition2" - }, - { - "Condition": "FunctionCondition3" - }, - { - "Condition": "FunctionCondition4" - }, - { - "Condition": "FunctionCondition5" - }, - { - "Condition": "FunctionCondition6" - } + "FunctionCondition": { + "Fn::Equals": [ + true, + false ] }, - "FunctionCondition6": { + "FunctionCondition2": { "Fn::Equals": [ true, false ] }, - "FunctionCondition5": { + "FunctionCondition3": { "Fn::Equals": [ true, false @@ -40,20 +24,23 @@ false ] }, - "FunctionCondition3": { + "FunctionCondition5": { "Fn::Equals": [ true, false ] }, - "FunctionCondition2": { + "FunctionCondition6": { "Fn::Equals": [ true, false ] }, - "ServerlessRestApiSLASHusersPathCondition": { + "ServerlessRestApiCondition": { "Fn::Or": [ + { + "Condition": "FunctionCondition" + }, { "Condition": "FunctionCondition2" }, @@ -71,159 +58,156 @@ } ] }, - "FunctionCondition": { - "Fn::Equals": [ - true, - false + "ServerlessRestApiSLASHusersPathCondition": { + "Fn::Or": [ + { + "Condition": "FunctionCondition2" + }, + { + "Condition": "FunctionCondition3" + }, + { + "Condition": "FunctionCondition4" + }, + { + "Condition": "FunctionCondition5" + }, + { + "Condition": "FunctionCondition6" + } ] } }, "Resources": { - "MyFunction4": { - "Type": "AWS::Lambda::Function", + "MyFunction": { + "Condition": "FunctionCondition", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction4Role", + "MyFunctionRole", "Arn" ] }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition4" + "Type": "AWS::Lambda::Function" }, - "MyFunction6": { - "Type": "AWS::Lambda::Function", + "MyFunction2": { + "Condition": "FunctionCondition2", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction6Role", + "MyFunction2Role", "Arn" ] }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction2Role": { + "Condition": "FunctionCondition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition6" + "Type": "AWS::IAM::Role" }, "MyFunction2WithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Condition": "FunctionCondition2", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction2" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "FunctionCondition2" + "Type": "AWS::Lambda::Permission" }, "MyFunction3": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition3", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Role": { - "Fn::GetAtt": [ - "MyFunction3Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "FunctionCondition3" - }, - "MyFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, "Role": { "Fn::GetAtt": [ - "MyFunction2Role", + "MyFunction3Role", "Arn" ] }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition2" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment6b0de9dc9a" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Function" }, - "MyFunction5Role": { - "Type": "AWS::IAM::Role", + "MyFunction3Role": { + "Condition": "FunctionCondition3", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -236,56 +220,71 @@ ] } } - ] - } - }, - "Condition": "FunctionCondition5" - }, - "MyFunction2Role": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction3WithLambdaTokenAuthorizerPermissionProd": { + "Condition": "FunctionCondition3", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } }, - "Condition": "FunctionCondition2" + "Type": "AWS::Lambda::Permission" }, - "MyFunction4Role": { - "Type": "AWS::IAM::Role", + "MyFunction4": { + "Condition": "FunctionCondition4", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunction4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction4Role": { + "Condition": "FunctionCondition4", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -298,19 +297,51 @@ ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction4WithLambdaTokenAuthorizerPermissionProd": { + "Condition": "FunctionCondition4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } }, - "Condition": "FunctionCondition4" + "Type": "AWS::Lambda::Permission" }, "MyFunction5": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition5", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunction5Role", @@ -320,27 +351,17 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition5" + "Type": "AWS::Lambda::Function" }, - "MyFunction6Role": { - "Type": "AWS::IAM::Role", + "MyFunction5Role": { + "Condition": "FunctionCondition5", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -353,66 +374,71 @@ ] } } - ] - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "FunctionCondition6" + "Type": "AWS::IAM::Role" }, - "ServerlessRestApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunction5WithLambdaRequestAuthorizerPermissionProd": { + "Condition": "FunctionCondition5", "Properties": { "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction5" + }, "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunction6": { + "Condition": "FunctionCondition6", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunction6Role", + "Arn" ] - } - }, - "Condition": "FunctionCondition" - }, - "MyFunction3Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction6Role": { + "Condition": "FunctionCondition6", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -425,131 +451,47 @@ ] } } - ] - } - }, - "Condition": "FunctionCondition3" - }, - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" + ], + "Version": "2012-10-17" }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition" - }, - "MyFunction4WithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction4" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition4" - }, - "ServerlessRestApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::IAM::Role" }, - "MyFunction5WithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunction6WithDefaultAuthorizerPermissionProd": { + "Condition": "FunctionCondition6", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFunction5" + "Ref": "MyFunction6" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition5" - }, - "ServerlessRestApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", { "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -562,75 +504,52 @@ ] } } - ] - } - }, - "Condition": "FunctionCondition" - }, - "ServerlessRestApiDeployment6b0de9dc9a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: 6b0de9dc9a2450a248988d39c61e2ee23b257724", - "StageName": "Stage" + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::IAM::Role" }, - "MyFunction3WithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerPermissionProd": { + "Condition": "FunctionCondition", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFunction3" + "Ref": "MyFunction" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition3" - }, - "MyFunction6WithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction6" - }, "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "FunctionCondition6" + "Type": "AWS::Lambda::Permission" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { @@ -641,6 +560,12 @@ "Fn::If": [ "FunctionCondition", { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -655,13 +580,7 @@ } ] } - }, - "security": [ - { - "NONE": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -678,158 +597,158 @@ "Fn::If": [ "ServerlessRestApiSLASHusersPathCondition", { - "put": { + "delete": { "Fn::If": [ - "FunctionCondition6", + "FunctionCondition5", { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition6", + "FunctionCondition5", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction6.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction5.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "api_key": [] - }, - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "patch": { + "get": { "Fn::If": [ - "FunctionCondition4", + "FunctionCondition3", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition4", + "FunctionCondition3", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction4.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction3.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "post": { + "patch": { "Fn::If": [ - "FunctionCondition2", + "FunctionCondition4", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition2", + "FunctionCondition4", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction2.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction4.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyCognitoAuthMultipleUserPools": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "get": { + "post": { "Fn::If": [ - "FunctionCondition3", + "FunctionCondition2", { + "responses": {}, + "security": [ + { + "MyCognitoAuthMultipleUserPools": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition3", + "FunctionCondition2", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction3.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "delete": { + "put": { "Fn::If": [ - "FunctionCondition5", + "FunctionCondition6", { + "responses": {}, + "security": [ + { + "api_key": [] + }, + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition5", + "FunctionCondition6", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction5.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction6.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -843,39 +762,41 @@ ] } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "MyCognitoAuth": { "in": "header", + "name": "MyAuthorizationHeader", "type": "apiKey", - "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - } + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" }, - "x-amazon-apigateway-authtype": "custom" + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "api_key": { + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", "type": "apiKey", - "name": "x-api-key", - "in": "header" + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, "MyLambdaRequestAuth": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", "authorizerUri": { "Fn::Sub": [ "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -884,29 +805,17 @@ } ] }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" }, - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, "MyLambdaTokenAuth": { "in": "header", - "type": "apiKey", "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ @@ -916,26 +825,36 @@ } ] }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" + "identityValidationExpression": "mycustomauthexpression", + "type": "token" }, "x-amazon-apigateway-authtype": "custom" }, - "MyCognitoAuthMultipleUserPools": { + "MyLambdaTokenAuthNoneFunctionInvokeRole": { "in": "header", + "name": "Authorization", "type": "apiKey", - "name": "MyAuthorizationHeader2", "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "type": "token" }, - "x-amazon-apigateway-authtype": "cognito_user_pools" + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -946,7 +865,88 @@ "endpointConfigurationTypes": "REGIONAL" } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment6b0de9dc9a": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Description": "RestApi deployment id: 6b0de9dc9a2450a248988d39c61e2ee23b257724", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiMyLambdaRequestAuthAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiMyLambdaTokenAuthAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment6b0de9dc9a" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/implicit_api_with_many_conditions.json b/tests/translator/output/aws-cn/implicit_api_with_many_conditions.json index bfe56a5225..8a57fe6d31 100644 --- a/tests/translator/output/aws-cn/implicit_api_with_many_conditions.json +++ b/tests/translator/output/aws-cn/implicit_api_with_many_conditions.json @@ -1,49 +1,49 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "Cond5": { + "Cond": { "Fn::Equals": [ true, false ] }, - "Cond4": { + "Cond1": { "Fn::Equals": [ true, false ] }, - "Cond7": { + "Cond2": { "Fn::Equals": [ true, false ] }, - "Cond6": { + "Cond3": { "Fn::Equals": [ true, false ] }, - "Cond1": { + "Cond4": { "Fn::Equals": [ true, false ] }, - "Cond3": { + "Cond5": { "Fn::Equals": [ true, false ] }, - "Cond2": { + "Cond6": { "Fn::Equals": [ true, false ] }, - "Cond9": { + "Cond7": { "Fn::Equals": [ true, false @@ -55,7 +55,13 @@ false ] }, - "Cond": { + "Cond9": { + "Fn::Equals": [ + true, + false + ] + }, + "MyCondition": { "Fn::Equals": [ true, false @@ -105,12 +111,6 @@ } ] }, - "MyCondition": { - "Fn::Equals": [ - true, - false - ] - }, "ServerlessRestApiSLASHsubPathCondition": { "Fn::Or": [ { @@ -122,950 +122,69 @@ ] } }, + "Description": "A template to test for implicit API condition handling.", "Resources": { - "helloworld7ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld7" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond7" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5d9ff7b9fd" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "helloworld1Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond1" - }, - "helloworld7": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld7Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond7" - }, - "helloworld6": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld6Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond6" - }, - "helloworldRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond" - }, - "helloworld4": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld4Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond4" - }, - "helloworld3": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld3Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond3" - }, - "helloworld2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond2" - }, - "helloworld1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond1" - }, - "helloworld9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld9Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond9" - }, - "helloApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "hello" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "MyCondition" - }, - "helloworld2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond2" - }, - "helloworld3ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond3" - }, - "helloworld1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond1" - }, - "helloworld8": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld8Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond8" - }, - "helloworld6ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld6" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond6" - }, - "ServerlessRestApiDeployment5d9ff7b9fd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5d9ff7b9fd3c20ed584298527fb932741f6a34fa", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "helloworld4Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond4" - }, - "helloworldApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond" - }, - "helloworld9Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld5ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld5" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond5" - }, - "helloworld8ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld8" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond8" - }, - "helloRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "MyCondition" - }, - "helloworld8Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond8" - }, - "helloworld": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworldRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond" - }, - "helloworld5Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond5" - }, - "hello": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "MyCondition" - }, - "helloworld5": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld5Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond5" - }, - "helloworld9ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld9" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld6Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond6" - }, - "helloworld7Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond7" - }, - "helloworld2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond2" - }, - "helloworld3Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond3" - }, - "helloworld4ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld4" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond4" - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/sub": { "Fn::If": [ "ServerlessRestApiSLASHsubPathCondition", { - "post": { + "get": { "Fn::If": [ - "Cond", + "MyCondition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "MyCondition", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "get": { + "post": { "Fn::If": [ - "MyCondition", + "Cond", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "MyCondition", + "Cond", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1078,30 +197,30 @@ } ] }, - "/sub8": { + "/sub1": { "Fn::If": [ - "Cond8", + "Cond1", { "post": { "Fn::If": [ - "Cond8", + "Cond1", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond8", + "Cond1", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1114,30 +233,30 @@ } ] }, - "/sub9": { + "/sub2": { "Fn::If": [ - "Cond9", + "Cond2", { "post": { "Fn::If": [ - "Cond9", + "Cond2", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond9", + "Cond2", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1150,30 +269,30 @@ } ] }, - "/sub1": { + "/sub3": { "Fn::If": [ - "Cond1", + "Cond3", { "post": { "Fn::If": [ - "Cond1", + "Cond3", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond1", + "Cond3", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1186,30 +305,30 @@ } ] }, - "/sub2": { + "/sub4": { "Fn::If": [ - "Cond2", + "Cond4", { "post": { "Fn::If": [ - "Cond2", + "Cond4", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond2", + "Cond4", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1222,30 +341,30 @@ } ] }, - "/sub3": { + "/sub5": { "Fn::If": [ - "Cond3", + "Cond5", { "post": { "Fn::If": [ - "Cond3", + "Cond5", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond3", + "Cond5", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1258,30 +377,30 @@ } ] }, - "/sub4": { + "/sub6": { "Fn::If": [ - "Cond4", + "Cond6", { "post": { "Fn::If": [ - "Cond4", + "Cond6", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond4", + "Cond6", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1294,30 +413,30 @@ } ] }, - "/sub5": { + "/sub7": { "Fn::If": [ - "Cond5", + "Cond7", { "post": { "Fn::If": [ - "Cond5", + "Cond7", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond5", + "Cond7", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1330,30 +449,30 @@ } ] }, - "/sub6": { + "/sub8": { "Fn::If": [ - "Cond6", + "Cond8", { "post": { "Fn::If": [ - "Cond6", + "Cond8", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond6", + "Cond8", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1366,30 +485,30 @@ } ] }, - "/sub7": { + "/sub9": { "Fn::If": [ - "Cond7", + "Cond9", { "post": { "Fn::If": [ - "Cond7", + "Cond9", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond7", + "Cond9", { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1402,20 +521,901 @@ } ] } - }, - "swagger": "2.0" + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5d9ff7b9fd": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Description": "RestApi deployment id: 5d9ff7b9fd3c20ed584298527fb932741f6a34fa", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5d9ff7b9fd" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "hello": { + "Condition": "MyCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloApiEventPermissionProd": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "hello" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloRole": { + "Condition": "MyCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld": { + "Condition": "Cond", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworldRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1": { + "Condition": "Cond1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1ApiEventPermissionProd": { + "Condition": "Cond1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1Role": { + "Condition": "Cond1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld2": { + "Condition": "Cond2", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld2ApiEventPermissionProd": { + "Condition": "Cond2", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld2Role": { + "Condition": "Cond2", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld3": { + "Condition": "Cond3", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld3Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld3ApiEventPermissionProd": { + "Condition": "Cond3", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld3Role": { + "Condition": "Cond3", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld4": { + "Condition": "Cond4", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld4ApiEventPermissionProd": { + "Condition": "Cond4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld4Role": { + "Condition": "Cond4", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld5": { + "Condition": "Cond5", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld5Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld5ApiEventPermissionProd": { + "Condition": "Cond5", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld5" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld5Role": { + "Condition": "Cond5", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld6": { + "Condition": "Cond6", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld6ApiEventPermissionProd": { + "Condition": "Cond6", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld6" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld6Role": { + "Condition": "Cond6", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld7": { + "Condition": "Cond7", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld7Role", + "Arn" ] }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld7ApiEventPermissionProd": { + "Condition": "Cond7", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld7" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld7Role": { + "Condition": "Cond7", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld8": { + "Condition": "Cond8", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld8Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld8ApiEventPermissionProd": { + "Condition": "Cond8", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld8" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" + }, + "helloworld8Role": { + "Condition": "Cond8", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld9": { + "Condition": "Cond9", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld9Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld9ApiEventPermissionProd": { + "Condition": "Cond9", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld9" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld9Role": { + "Condition": "Cond9", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworldApiEventPermissionProd": { + "Condition": "Cond", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworldRole": { + "Condition": "Cond", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "A template to test for implicit API condition handling." + } } diff --git a/tests/translator/output/aws-cn/implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/aws-cn/implicit_api_with_serverless_rest_api_resource.json index 8acd95d0f7..79f84eaea0 100644 --- a/tests/translator/output/aws-cn/implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/aws-cn/implicit_api_with_serverless_rest_api_resource.json @@ -1,290 +1,290 @@ { "Resources": { - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RestApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "RestApiFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "RestApiFunctionCompleteItemPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "GetHtmlFunction" - }, + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentb5184bf2cc" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "RestApiFunctionGetListPermissionProd": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeploymentb5184bf2cc": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: b5184bf2cccc18d4a1efae523c2c88fd5282c8a3", - "StageName": "Stage" - } - }, - "RestApiFunctionGetListPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/{proxy+}": { - "x-amazon-apigateway-any-method": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/complete": { - "post": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "RestApiFunctionCompleteItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentb5184bf2cc": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: b5184bf2cccc18d4a1efae523c2c88fd5282c8a3", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentb5184bf2cc" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-cn/implicit_http_api.json b/tests/translator/output/aws-cn/implicit_http_api.json index c23badb552..db1adcdf17 100644 --- a/tests/translator/output/aws-cn/implicit_http_api.json +++ b/tests/translator/output/aws-cn/implicit_http_api.json @@ -1,275 +1,275 @@ { "Resources": { - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "HttpApiFunction": { "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunction2": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunction2Basic2Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/basic2", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] } - } - }, - "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HttpApiFunction2PathParametersPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HttpApiFunction2Role": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunction2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "HttpApiFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic2": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } - }, - "/get/{something}/with/{params}": { + }, + "/basic": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {}, - "parameters": [ - { - "required": true, - "name": "something", - "in": "path" - }, - { - "required": true, - "name": "params", - "in": "path" + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - ] + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/basic2": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" + } + } } - }, - "/basic": { + }, + "/get/{something}/with/{params}": { "post": { + "parameters": [ + { + "in": "path", + "name": "something", + "required": true + }, + { + "in": "path", + "name": "params", + "required": true + } + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" + } + } } } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } - }, - "HttpApiFunction2PathParametersPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - } - }, - "HttpApiFunction2Basic2Permission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/basic2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/implicit_http_api_auth_and_simple_case.json b/tests/translator/output/aws-cn/implicit_http_api_auth_and_simple_case.json index b3e0950108..02a7388141 100644 --- a/tests/translator/output/aws-cn/implicit_http_api_auth_and_simple_case.json +++ b/tests/translator/output/aws-cn/implicit_http_api_auth_and_simple_case.json @@ -1,230 +1,230 @@ { "Resources": { - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "RestApiFunction": { "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/defaultauth": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - }, - "/oauth2": { - "post": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + } + } + } + }, + "/defaultauth": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + } + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/noneauth": { + "post": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, + } + } + } + }, + "/oauth2": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - }, - "/noneauth": { - "post": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "NONE": [] } - ], - "responses": {} + } } - }, + }, "/scope3": { "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + "responses": {}, "security": [ { "oauth2Auth": [ "scope3" ] } - ], - "responses": {} - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } } } } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/implicit_http_api_with_many_conditions.json b/tests/translator/output/aws-cn/implicit_http_api_with_many_conditions.json index 90f1f1c0f9..bb8a662e2b 100644 --- a/tests/translator/output/aws-cn/implicit_http_api_with_many_conditions.json +++ b/tests/translator/output/aws-cn/implicit_http_api_with_many_conditions.json @@ -1,1506 +1,1506 @@ { - "AWSTemplateFormatVersion": "2010-09-09", + "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "Cond5": { + "Cond": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond4": { + }, + "Cond1": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond7": { + }, + "Cond2": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond6": { + }, + "Cond3": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond1": { + }, + "Cond4": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond3": { + }, + "Cond5": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond2": { + }, + "Cond6": { "Fn::Equals": [ - true, + true, false ] - }, - "ServerlessHttpApiCondition": { - "Fn::Or": [ - { - "Condition": "MyCondition" - }, - { - "Condition": "ServerlessHttpApiCondition1" - } - ] - }, - "Cond9": { + }, + "Cond7": { "Fn::Equals": [ - true, + true, false ] - }, + }, "Cond8": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond": { + }, + "Cond9": { + "Fn::Equals": [ + true, + false + ] + }, + "MyCondition": { "Fn::Equals": [ - true, + true, false ] - }, + }, + "ServerlessHttpApiCondition": { + "Fn::Or": [ + { + "Condition": "MyCondition" + }, + { + "Condition": "ServerlessHttpApiCondition1" + } + ] + }, "ServerlessHttpApiCondition1": { "Fn::Or": [ { "Condition": "Cond" - }, + }, { "Condition": "Cond1" - }, + }, { "Condition": "Cond2" - }, + }, { "Condition": "Cond3" - }, + }, { "Condition": "Cond4" - }, + }, { "Condition": "Cond5" - }, + }, { "Condition": "Cond6" - }, + }, { "Condition": "Cond7" - }, + }, { "Condition": "Cond8" - }, + }, { "Condition": "Cond9" } ] - }, - "MyCondition": { - "Fn::Equals": [ - true, - false - ] } - }, - "Description": "A template to test for implicit HttpApi condition handling.", + }, + "Description": "A template to test for implicit HttpApi condition handling.", "Resources": { - "helloworld9HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld9" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld9Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "Cond9" - }, - "helloworld2HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond2" - }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", + "Condition": "ServerlessHttpApiCondition", "Properties": { "Body": { + "components": { + "securitySchemes": { + "oauth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/hello/again": { + "$default": { "Fn::If": [ - "Cond", + "Cond", { - "get": { + "x-amazon-apigateway-any-method": { "Fn::If": [ - "Cond", + "Cond", { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "oauth2": [ + "scope4" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "Cond", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub": { + }, + "/hello/again": { "Fn::If": [ - "MyCondition", + "Cond", { "get": { "Fn::If": [ - "MyCondition", + "Cond", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "MyCondition", + "Cond", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub8": { + }, + "/sub": { "Fn::If": [ - "Cond8", + "MyCondition", { - "post": { + "get": { "Fn::If": [ - "Cond8", + "MyCondition", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond8", + "MyCondition", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub9": { + }, + "/sub1": { "Fn::If": [ - "Cond9", + "Cond1", { "post": { "Fn::If": [ - "Cond9", + "Cond1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond9", + "Cond1", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "$default": { + }, + "/sub2": { "Fn::If": [ - "Cond", + "Cond2", { - "x-amazon-apigateway-any-method": { + "post": { "Fn::If": [ - "Cond", + "Cond2", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "Cond2", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "security": [ - { - "oauth2": [ - "scope4" - ] } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub1": { + }, + "/sub3": { "Fn::If": [ - "Cond1", + "Cond3", { "post": { "Fn::If": [ - "Cond1", + "Cond3", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond1", + "Cond3", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub2": { + }, + "/sub4": { "Fn::If": [ - "Cond2", + "Cond4", { "post": { "Fn::If": [ - "Cond2", + "Cond4", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond2", + "Cond4", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub3": { + }, + "/sub5": { "Fn::If": [ - "Cond3", + "Cond5", { "post": { "Fn::If": [ - "Cond3", + "Cond5", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond3", + "Cond5", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub4": { + }, + "/sub6": { "Fn::If": [ - "Cond4", + "Cond6", { "post": { "Fn::If": [ - "Cond4", + "Cond6", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond4", + "Cond6", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub5": { + }, + "/sub7": { "Fn::If": [ - "Cond5", + "Cond7", { "post": { "Fn::If": [ - "Cond5", + "Cond7", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond5", + "Cond7", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub6": { + }, + "/sub8": { "Fn::If": [ - "Cond6", + "Cond8", { "post": { "Fn::If": [ - "Cond6", + "Cond8", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond6", + "Cond8", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub7": { + }, + "/sub9": { "Fn::If": [ - "Cond7", + "Cond9", { "post": { "Fn::If": [ - "Cond7", + "Cond9", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond7", + "Cond9", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - } - } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - }, - "Condition": "ServerlessHttpApiCondition" - }, - "helloworld6HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Condition": "ServerlessHttpApiCondition", + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "RouteSettings": { + "$default": { + "Fn::If": [ + "Cond", + { + "ThrottlingBurstLimit": 200 + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "GET /sub": { + "Fn::If": [ + "MyCondition", + { + "ThrottlingBurstLimit": 200 + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "hello": { + "Condition": "MyCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloHttpApiEventPermission": { + "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld6" - }, + "Ref": "hello" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond6" - }, - "helloworld1Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloRole": { + "Condition": "MyCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond1" - }, - "helloworld7": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld1": { + "Condition": "Cond1", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld7Role", + "helloworld1Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond7" - }, - "helloworld6": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld6Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond6" - }, - "helloworld5": { - "Type": "AWS::Lambda::Function", + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1099": { + "Condition": "Cond", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld5Role", + "helloworld1099Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond5" - }, - "helloworld1099Role": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1099HttpApiEventPermission": { + "Condition": "Cond", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1099" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1099Role": { + "Condition": "Cond", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond" - }, - "helloworld3": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld1HttpApiEventPermission": { + "Condition": "Cond1", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld3Role", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond3" - }, - "helloworld2": { - "Type": "AWS::Lambda::Function", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1Role": { + "Condition": "Cond1", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond2" - }, - "helloworld1": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld2": { + "Condition": "Cond2", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld1Role", + "helloworld2Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond1" - }, - "helloworld9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld9Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond9" - }, - "hello": { - "Type": "AWS::Lambda::Function", + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld2HttpApiEventPermission": { + "Condition": "Cond2", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "MyCondition" - }, - "helloRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld2Role": { + "Condition": "Cond2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "MyCondition" - }, - "helloworld7HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld7" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond7" - }, - "helloHttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld3": { + "Condition": "Cond3", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "hello" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld3Role", + "Arn" ] - } - }, - "Condition": "MyCondition" - }, - "helloworld1HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld3HttpApiEventPermission": { + "Condition": "Cond3", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld1" - }, + "Ref": "helloworld3" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond1" - }, - "helloworld5Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld3Role": { + "Condition": "Cond3", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond5" - }, + }, + "Type": "AWS::IAM::Role" + }, + "helloworld4": { + "Condition": "Cond4", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld4HttpApiEventPermission": { + "Condition": "Cond4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "helloworld4Role": { - "Type": "AWS::IAM::Role", + "Condition": "Cond4", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond4" - }, - "helloworld1099HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld5": { + "Condition": "Cond5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld1099" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld5Role", + "Arn" ] - } - }, - "Condition": "Cond" - }, + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "helloworld5HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "Cond5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "helloworld5" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond5" - }, - "helloworld7Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld5Role": { + "Condition": "Cond5", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond7" - }, - "helloworld2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld6": { + "Condition": "Cond6", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld6HttpApiEventPermission": { + "Condition": "Cond6", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld6" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld6Role": { + "Condition": "Cond6", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond2" - }, - "helloworld8Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld7": { + "Condition": "Cond7", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld7Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld7HttpApiEventPermission": { + "Condition": "Cond7", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld7" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld7Role": { + "Condition": "Cond7", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond8" - }, - "helloworld4": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld8": { + "Condition": "Cond8", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld4Role", + "helloworld8Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond4" - }, - "helloworld1099": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld1099Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond" - }, + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "helloworld8HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "Cond8", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "helloworld8" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond8" - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "RouteSettings": { - "GET /sub": { - "Fn::If": [ - "MyCondition", - { - "ThrottlingBurstLimit": 200 - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "$default": { - "Fn::If": [ - "Cond", - { - "ThrottlingBurstLimit": 200 - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "ServerlessHttpApiCondition" - }, - "helloworld3Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld8Role": { + "Condition": "Cond8", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond3" - }, - "helloworld8": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld9": { + "Condition": "Cond9", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld8Role", + "helloworld9Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond8" - }, - "helloworld4HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld9HttpApiEventPermission": { + "Condition": "Cond9", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld4" - }, + "Ref": "helloworld9" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond4" - }, - "helloworld6Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld9Role": { + "Condition": "Cond9", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond6" - }, - "helloworld3HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond3" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/inline_precedence.json b/tests/translator/output/aws-cn/inline_precedence.json index 5a3b8edd7f..51cf5d4a6d 100644 --- a/tests/translator/output/aws-cn/inline_precedence.json +++ b/tests/translator/output/aws-cn/inline_precedence.json @@ -1,56 +1,56 @@ { - "Resources": { - "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "Resources": { + "HelloWorldFunction": { + "Properties": { + "Code": { + "ZipFile": "\"def lambda_handler():\n pass\"\n" + }, + "Handler": "index.lambda_handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.8", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.lambda_handler", - "Code": { - "ZipFile": "\"def lambda_handler():\n pass\"\n" - }, - "Role": { - "Fn::GetAtt": [ - "HelloWorldFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.8", - "Tags": [ + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/intrinsic_functions.json b/tests/translator/output/aws-cn/intrinsic_functions.json index 88052c283c..7a93d4676d 100644 --- a/tests/translator/output/aws-cn/intrinsic_functions.json +++ b/tests/translator/output/aws-cn/intrinsic_functions.json @@ -8,14 +8,14 @@ } }, "Parameters": { - "CodeKey": { - "Default": "key", - "Type": "String" - }, "CodeBucket": { "Default": "sam-demo-bucket", "Type": "String" }, + "CodeKey": { + "Default": "key", + "Type": "String" + }, "FunctionName": { "Default": "MySuperFunctionName", "Type": "String" @@ -24,181 +24,114 @@ "Default": "SomeName", "Type": "String" }, + "RoleFieldName": { + "Default": "Role", + "Type": "String" + }, "TracingConfigParam": { "Default": "PassThrough", "Type": "String" - }, - "RoleFieldName": { - "Type": "String", - "Default": "Role" } }, "Resources": { - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiWithExplicitS3Uri": { + "Condition": "TrueCondition", "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } - }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, - "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "DeadLetterConfig": { - "TargetArn": { - "Fn::GetAtt": [ - "SqsDlqQueue", - "Arn" - ] - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", - "Arn" - ] + "Bucket": "mybucket", + "Key": "mykey", + "Version": 3 }, - "Runtime": "python2.7" - } - }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { "EndpointConfiguration": { "Types": [ "REGIONAL" ] }, - "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", - "Key": "mykey" - }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } }, - "Condition": "TrueCondition" + "Type": "AWS::ApiGateway::RestApi" }, - "MyExplicitApiDeployment7145dd00ce": { - "Type": "AWS::ApiGateway::Deployment", + "ApiWithExplicitS3UriDeployment7ab7044581": { + "Condition": "TrueCondition", "Properties": { + "Description": "RestApi deployment id: 7ab7044581d53db4957e668f336b462f099db4af", "RestApiId": { - "Ref": "MyExplicitApi" + "Ref": "ApiWithExplicitS3Uri" }, - "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "ApiWithExplicitS3UridevStage": { + "Condition": "TrueCondition", + "Properties": { + "DeploymentId": { + "Ref": "ApiWithExplicitS3UriDeployment7ab7044581" + }, + "RestApiId": { + "Ref": "ApiWithExplicitS3Uri" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "DynamoDBFunction": { "Properties": { - "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" }, + "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", + "DynamoDBFunctionRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "DynamoDBFunctionMyDDBStream": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Ref": "SnsDlqQueue" - }, - "Effect": "Allow" + "BatchSize": 200, + "EventSourceArn": { + "Fn::GetAtt": [ + "MyTable", + "StreamArn" + ] + }, + "FilterCriteria": { + "Fn::Select": [ + "1", + [ + {}, + { + "Filters": { + "Pattern": "{\"value\": \"b\"}" } - ] - } - } - ], + } + ] + ] + }, + "FunctionName": { + "Ref": "DynamoDBFunction" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "DynamoDBFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -211,21 +144,33 @@ ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyOtherFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithExplicitS3Uri": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "S3Bucket": "mybucket", + "S3Key": "mykey", + "S3ObjectVersion": "MyVersion" }, - "Handler": "hello.handler", + "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ - "MyOtherFunctionRole", + "FunctionWithExplicitS3UriRole", "Arn" ] }, @@ -236,13 +181,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyOtherFunctionRole": { - "Type": "AWS::IAM::Role", + "FunctionWithExplicitS3UriRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -255,7 +199,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -266,10 +211,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "FunctionWithValidGetAttAndRef": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -291,16 +236,67 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunction": { - "Type": "AWS::Lambda::Function", + "MyExplicitApi": { "Properties": { - "TracingConfig": { - "Mode": { - "Ref": "TracingConfigParam" - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "swagger.yaml" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": { + "Ref": "MyExplicitApiName" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyExplicitApiDeployment7145dd00ce": { + "Properties": { + "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyExplicitApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyExplicitApiDeployment7145dd00ce" + }, + "RestApiId": { + "Ref": "MyExplicitApi" }, + "StageName": "dev", + "Variables": { + "FunctionName": { + "Fn::Sub": "${MyFunction}" + }, + "Var2": { + "Fn::Join": [ + "join ", + [ + "some value ", + "with some other value" + ] + ] + } + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { "Code": { "S3Bucket": { "Ref": "CodeBucket" @@ -321,12 +317,6 @@ "FunctionName": { "Fn::Sub": "${FunctionName}" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": { "Fn::Sub": [ "${filename}.handler", @@ -349,14 +339,45 @@ "4.3" ] ] + }, + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "TracingConfig": { + "Mode": { + "Ref": "TracingConfigParam" + } } - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithExplicitS3UriRole": { - "Type": "AWS::IAM::Role", + "MyFunctionMyApiPermissiondev": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyNewRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -369,48 +390,56 @@ ] } } - ] + ], + "Version": "2012-10-17" }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "cloudwatch:*", + "logs:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "lambdaRole" } ] - } - }, - "ApiWithExplicitS3UriDeployment7ab7044581": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: 7ab7044581d53db4957e668f336b462f099db4af", - "StageName": "Stage" }, - "Condition": "TrueCondition" + "Type": "AWS::IAM::Role" }, - "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", + "MyOtherFunction": { "Properties": { - "DeploymentId": { - "Ref": "ApiWithExplicitS3UriDeployment7ab7044581" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyOtherFunctionRole", + "Arn" + ] }, - "StageName": "dev" + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "TrueCondition" + "Type": "AWS::Lambda::Function" }, - "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", + "MyOtherFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -423,22 +452,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -449,12 +478,6 @@ "Ref": "SnsDlqQueue" } }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -462,81 +485,64 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "MySnsDlqLambdaFunctionRole": { "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "Policies": [ { - "AttributeName": "id", - "AttributeType": "S" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": { + "Ref": "SnsDlqQueue" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } - }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, - "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "stream.ddb_handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Role": { - "Fn::GetAtt": [ - "DynamoDBFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -550,12 +556,6 @@ ] } }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -563,125 +563,19 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyExplicitApiDeployment7145dd00ce" - }, - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "Variables": { - "FunctionName": { - "Fn::Sub": "${MyFunction}" - }, - "Var2": { - "Fn::Join": [ - "join ", - [ - "some value ", - "with some other value" - ] - ] - } - }, - "StageName": "dev" - } - }, - "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 200, - "FunctionName": { - "Ref": "DynamoDBFunction" - }, - "StartingPosition": "LATEST", - "EventSourceArn": { - "Fn::GetAtt": [ - "MyTable", - "StreamArn" - ] - }, - "FilterCriteria": { - "Fn::Select": [ - "1", - [ - {}, - { - "Filters": { - "Pattern": "{\"value\": \"b\"}" - } - } - ] - ] - } - } - }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "stream.ddb_handler", - "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", - "Arn" - ] - }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyExplicitApiDeployment7145dd00ce": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", - "StageName": "Stage" - } - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Version": 3, - "Bucket": "mybucket", - "Key": "mykey" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } }, - "Condition": "TrueCondition" + "Type": "AWS::Lambda::Function" }, "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -694,145 +588,70 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ "SqsDlqQueue", "Arn" ] - }, - "Effect": "Allow" + } } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "MyTable": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ + "AttributeDefinitions": [ { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Ref": "SnsDlqQueue" - }, - "Effect": "Allow" - } - ] - } + "AttributeName": "id", + "AttributeType": "S" } ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyNewRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + "KeySchema": [ { - "PolicyName": "lambdaRole", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "cloudwatch:*", - "logs:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } + "AttributeName": "id", + "KeyType": "HASH" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyExplicitApi" - } - } - ] + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" } - } + }, + "Type": "AWS::DynamoDB::Table" + }, + "SnsDlqQueue": { + "Type": "AWS::SNS::Topic" + }, + "SqsDlqQueue": { + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/iot_rule.json b/tests/translator/output/aws-cn/iot_rule.json index c54b46f7fb..451f94bd15 100644 --- a/tests/translator/output/aws-cn/iot_rule.json +++ b/tests/translator/output/aws-cn/iot_rule.json @@ -1,31 +1,79 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, "Resources": { + "IoTRuleFunc": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "IoTRuleFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "IoTRuleFuncMyIoTRule": { - "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { - "AwsIotSqlVersion": "beta", "Actions": [ { "Lambda": { "FunctionArn": { "Fn::GetAtt": [ - "IoTRuleFunc", + "IoTRuleFunc", "Arn" ] } } } - ], - "RuleDisabled": false, + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, "Sql": "SELECT * FROM 'topic/test'" } - } - }, + }, + "Type": "AWS::IoT::TopicRule" + }, + "IoTRuleFuncMyIoTRulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "IoTRuleFunc" + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + { + "RuleName": { + "Ref": "IoTRuleFuncMyIoTRule" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "IoTRuleFuncMyOtherIoTRule": { - "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { "Actions": [ @@ -33,52 +81,29 @@ "Lambda": { "FunctionArn": { "Fn::GetAtt": [ - "IoTRuleFunc", + "IoTRuleFunc", "Arn" ] } } } - ], - "RuleDisabled": false, + ], + "RuleDisabled": false, "Sql": "SELECT * FROM 'topic/test'" } - } - }, - "IoTRuleFuncMyIoTRulePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IoT::TopicRule" + }, + "IoTRuleFuncMyOtherIoTRulePermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "IoTRuleFunc" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", - { - "RuleName": { - "Ref": "IoTRuleFuncMyIoTRule" - } - } - ] - } - } - }, - "IoTRuleFuncMyOtherIoTRulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", + }, + "Principal": "iot.amazonaws.com", "SourceAccount": { "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", - "FunctionName": { - "Ref": "IoTRuleFunc" - }, + }, "SourceArn": { "Fn::Sub": [ "arn:aws-cn:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", @@ -89,63 +114,38 @@ } ] } - } - }, - "IoTRuleFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "IoTRuleFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "IoTRuleFuncRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/kinesis_intrinsics.json b/tests/translator/output/aws-cn/kinesis_intrinsics.json index 0484d1fdcc..b0ed275e6d 100644 --- a/tests/translator/output/aws-cn/kinesis_intrinsics.json +++ b/tests/translator/output/aws-cn/kinesis_intrinsics.json @@ -1,168 +1,168 @@ { - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + }, + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "FunctionResponseTypesValue": { + "Default": "ReportBatchItemFailures", + "Type": "String" + }, + "IntValue": { + "Default": 50, + "Type": "Number" + }, + "StartingPositionValue": { + "Default": "LATEST", + "Type": "String" + }, + "StringValue": { + "Default": "us-east-1", + "Type": "String" + } + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "stream.zip" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] - } - }, - "Resources": { - "MyLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionKinesisStream": { + "Properties": { + "BatchSize": { + "Ref": "IntValue" + }, + "BisectBatchOnFunctionError": { + "Fn::If": [ + "FalseCondition", + true, + false + ] + }, + "Enabled": { + "Fn::If": [ + "TrueCondition", + true, + false + ] + }, + "EventSourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":kinesis:", + { + "Ref": "AWS::Region" + }, + ":", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "Ref": "AWS::AccountId" + }, + ":stream/", + { + "Ref": "MyStream" } ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } ] - } - }, - "MyLambdaFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "IntValue" - }, - "FunctionName": { - "Ref": "MyLambdaFunction" - }, - "MaximumRecordAgeInSeconds": { - "Ref": "IntValue" - }, - "FunctionResponseTypes": [ - { - "Ref": "FunctionResponseTypesValue" - } - ], - "BatchSize": { - "Ref": "IntValue" - }, - "TumblingWindowInSeconds": { - "Ref": "IntValue" - }, - "Enabled": { - "Fn::If": [ - "TrueCondition", - true, - false - ] - }, - "EventSourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":kinesis:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":stream/", - { - "Ref": "MyStream" - } - ] - ] - }, - "StartingPosition": { - "Ref": "StartingPositionValue" - }, - "ParallelizationFactor": { - "Ref": "IntValue" - }, - "MaximumRetryAttempts": { - "Ref": "IntValue" - }, - "BisectBatchOnFunctionError": { - "Fn::If": [ - "FalseCondition", - true, - false - ] + }, + "FunctionName": { + "Ref": "MyLambdaFunction" + }, + "FunctionResponseTypes": [ + { + "Ref": "FunctionResponseTypesValue" } + ], + "MaximumBatchingWindowInSeconds": { + "Ref": "IntValue" + }, + "MaximumRecordAgeInSeconds": { + "Ref": "IntValue" + }, + "MaximumRetryAttempts": { + "Ref": "IntValue" + }, + "ParallelizationFactor": { + "Ref": "IntValue" + }, + "StartingPosition": { + "Ref": "StartingPositionValue" + }, + "TumblingWindowInSeconds": { + "Ref": "IntValue" } - }, - "MyStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } - }, - "MyLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "stream.zip" - }, - "Tags": [ + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - } - }, - "Parameters": { - "StringValue": { - "Default": "us-east-1", - "Type": "String" - }, - "IntValue": { - "Default": 50, - "Type": "Number" - }, - "FunctionResponseTypesValue": { - "Default": "ReportBatchItemFailures", - "Type": "String" - }, - "StartingPositionValue": { - "Default": "LATEST", - "Type": "String" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/layer_deletion_policy_precedence.json b/tests/translator/output/aws-cn/layer_deletion_policy_precedence.json index 8bb610ad00..f2b1de47a4 100644 --- a/tests/translator/output/aws-cn/layer_deletion_policy_precedence.json +++ b/tests/translator/output/aws-cn/layer_deletion_policy_precedence.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalLayer22b6609c3d": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Retain", "Properties": { "Content": { @@ -9,10 +8,10 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer" - } + }, + "Type": "AWS::Lambda::LayerVersion" }, "MinimalLayer2800a44a445": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Delete", "Properties": { "Content": { @@ -20,10 +19,10 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer2" - } + }, + "Type": "AWS::Lambda::LayerVersion" }, "MinimalLayer3ac07350a04": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Retain", "Properties": { "Content": { @@ -31,7 +30,8 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer3" - } + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/layers_all_properties.json b/tests/translator/output/aws-cn/layers_all_properties.json index 3520acb5bb..19550bc694 100644 --- a/tests/translator/output/aws-cn/layers_all_properties.json +++ b/tests/translator/output/aws-cn/layers_all_properties.json @@ -1,120 +1,120 @@ { "Outputs": { - "LayerSub": { - "Value": { - "Fn::Sub": "${MyLayerd04062b365}" - } - }, "FunctionAtt": { "Value": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] } - }, - "LayerName": { + }, + "FunctionName": { "Value": { - "Ref": "MyLayerd04062b365" + "Ref": "MyFunction" } - }, + }, "FunctionSub": { "Value": { "Fn::Sub": "${MyFunction}" } - }, - "FunctionName": { + }, + "LayerName": { "Value": { - "Ref": "MyFunction" + "Ref": "MyLayerd04062b365" + } + }, + "LayerSub": { + "Value": { + "Fn::Sub": "${MyLayerd04062b365}" } } - }, + }, "Parameters": { "LayerDeleteParam": { - "Default": "Delete", + "Default": "Delete", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Layers": [ - { - "Ref": "MyLayerd04062b365" - } - ], "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, - "Tags": [ + }, + "Handler": "app.handler", + "Layers": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "MyLayerd04062b365" } - ], - "Handler": "app.handler", + ], "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python3.6" - } - }, - "MyLayerd04062b365": { - "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "MyLayer" - } - }, - "MyLayerWithANamefda8c9ec8c": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "DifferentLayerName" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayerWithANamefda8c9ec8c": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "DifferentLayerName" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "MyLayerd04062b365": { + "DeletionPolicy": "Delete", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/layers_with_intrinsics.json b/tests/translator/output/aws-cn/layers_with_intrinsics.json index bd7cd1a9f3..ff8603acdc 100644 --- a/tests/translator/output/aws-cn/layers_with_intrinsics.json +++ b/tests/translator/output/aws-cn/layers_with_intrinsics.json @@ -1,167 +1,166 @@ { "Parameters": { "CompatibleArchitecturesList": { - "Type": "CommaDelimitedList", - "Default": "arm64,x86_64" + "Default": "arm64,x86_64", + "Type": "CommaDelimitedList" }, "CompatibleArchitecturesRef": { - "Type": "String", - "Default": "arm64" + "Default": "arm64", + "Type": "String" }, "LayerLicenseInfo": { "Default": "MIT-0 License", "Type": "String" }, - "LayerRuntimeList": { - "Type": "CommaDelimitedList" - }, "LayerNameParam": { "Default": "SomeLayerName", "Type": "String" }, + "LayerRuntimeList": { + "Type": "CommaDelimitedList" + }, "LayerRuntimeRefString": { "Default": "SomeRuntimeName", "Type": "String" } }, "Resources": { - "LayerWithNameIntrinsiccf8baed8b9": { + "LayerWithArchitecturesIntrinsicb79067ee69": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleArchitectures": { + "Ref": "CompatibleArchitecturesList" + }, "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "SomeLayerName" - } + "LayerName": "LayerWithArchitecturesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithRefNameIntrinsicRegion186db7e435": { + "LayerWithLicenseIntrinsic965c8d0c9b": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "cn-north-1" - } + "LayerName": "LayerWithLicenseIntrinsic", + "LicenseInfo": "MIT-0 License" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSubNameIntrinsicRegionfbc3f9f13d": { + "LayerWithMixedListRefRuntimesIntrinsic71fd80f592": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleRuntimes": [ + { + "Ref": "LayerRuntimeString" + }, + "SomeRuntimeNameString" + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": { - "Fn::Sub": "layer-cn-north-1" - } - } + "LayerName": "LayerWithMixedListRefRuntimesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithRuntimesIntrinsic1a006faa85": { + "LayerWithNameIntrinsiccf8baed8b9": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesIntrinsic", - "CompatibleRuntimes": { - "Ref": "LayerRuntimeList" - } - } + "LayerName": "SomeLayerName" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": { + "LayerWithRefNameIntrinsicRegion186db7e435": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleRuntimes": [ - { - "Ref": "LayerRuntimeRefString" - } - ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithSingleListRefRuntimesIntrinsic" + "LayerName": "cn-north-1" }, "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithMixedListRefRuntimesIntrinsic71fd80f592": { + "LayerWithRuntimesIntrinsic1a006faa85": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleRuntimes": [ - { - "Ref": "LayerRuntimeString" - }, - "SomeRuntimeNameString" - ], + "CompatibleRuntimes": { + "Ref": "LayerRuntimeList" + }, "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithMixedListRefRuntimesIntrinsic" + "LayerName": "LayerWithRuntimesIntrinsic" }, "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithLicenseIntrinsic965c8d0c9b": { + "LayerWithSingleListRefArchitecturesIntrinsicf8a2807636": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleArchitectures": [ + { + "Ref": "CompatibleArchitecturesRef" + } + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithLicenseIntrinsic", - "LicenseInfo": "MIT-0 License" - } + "LayerName": "LayerWithSingleListRefArchitecturesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSubNameIntrinsic6e9b477102": { - "Type": "AWS::Lambda::LayerVersion", + "LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": { "DeletionPolicy": "Retain", "Properties": { + "CompatibleRuntimes": [ + { + "Ref": "LayerRuntimeRefString" + } + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": { - "Fn::Sub": "layer-SomeLayerName" - } - } + "LayerName": "LayerWithSingleListRefRuntimesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithArchitecturesIntrinsicb79067ee69": { + "LayerWithSubNameIntrinsic6e9b477102": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithArchitecturesIntrinsic", - "CompatibleArchitectures": { - "Ref": "CompatibleArchitecturesList" + "LayerName": { + "Fn::Sub": "layer-SomeLayerName" } - } + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSingleListRefArchitecturesIntrinsicf8a2807636": { + "LayerWithSubNameIntrinsicRegionfbc3f9f13d": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleArchitectures": [ - { - "Ref": "CompatibleArchitecturesRef" - } - ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithSingleListRefArchitecturesIntrinsic" + "LayerName": { + "Fn::Sub": "layer-cn-north-1" + } }, "Type": "AWS::Lambda::LayerVersion" } } } - diff --git a/tests/translator/output/aws-cn/mixed_api_with_custom_domain_route53_multiple.json b/tests/translator/output/aws-cn/mixed_api_with_custom_domain_route53_multiple.json index 025997925c..d9a5bb35ac 100644 --- a/tests/translator/output/aws-cn/mixed_api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/aws-cn/mixed_api_with_custom_domain_route53_multiple.json @@ -1,193 +1,193 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", - "Resources": { - "MyRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", + "Resources": { + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "MyHttpApiApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV25fe29fe649" - }, - "Stage": { - "Ref": "MyHttpApiApiGatewayDefaultStage" - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "ApiGatewayDomainNameV25fe29fe649": { + "Properties": { + "DomainName": "admin.one.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyHttpApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyHttpApi" }, - "MyRestApiDeployment61887a4eed": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", - "RestApiId": { - "Ref": "MyRestApi" - }, - "StageName": "Stage" - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyHttpApiApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyHttpApi" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV25fe29fe649" }, - "ApiGatewayDomainNameV25fe29fe649": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.one.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } + "Stage": { + "Ref": "MyHttpApiApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "MyHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "MyHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyRestApiBasePathMapping": { + "Properties": { + "DomainName": { + "Ref": "ApiGatewayDomainName3fd2dbd8f8" }, - "MyRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyRestApiDeployment61887a4eed" - }, - "RestApiId": { - "Ref": "MyRestApi" - }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "RestApiId": { + "Ref": "MyRestApi" }, - "MyRestApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName3fd2dbd8f8" - }, - "RestApiId": { - "Ref": "MyRestApi" - }, - "Stage": { - "Ref": "MyRestApiProdStage" - } - } + "Stage": { + "Ref": "MyRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyRestApiDeployment61887a4eed": { + "Properties": { + "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "RestApiId": { + "Ref": "MyRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyRestApiDeployment61887a4eed" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "MyRestApi" }, - "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "abc123456", - "RecordSets": [ - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalDomainName" - ] - } - } - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "RecordSetGroup370194ff6e": { + "Properties": { + "HostedZoneId": "abc123456", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalDomainName" ] - } - } + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json index d100ffdc65..738feccd96 100644 --- a/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/aws-cn/no_implicit_api_with_serverless_rest_api_resource.json @@ -1,261 +1,261 @@ { "Resources": { "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "GetHtmlFunctionRole", + "GetHtmlFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" ] } } ] } - } - }, + }, + "Type": "AWS::S3::Bucket" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] - } - }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ThumbnailFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/resource_with_invalid_type.json b/tests/translator/output/aws-cn/resource_with_invalid_type.json index bde97009d5..d98f182563 100644 --- a/tests/translator/output/aws-cn/resource_with_invalid_type.json +++ b/tests/translator/output/aws-cn/resource_with_invalid_type.json @@ -1,17 +1,16 @@ { "Resources": { "FunctionInvalid": { - "Type": { - "AWS::Serverless::Function": "invalid_field" - }, "Properties": { "CodeUri": "s3://sam-demo-bucket/member_portal.zip", "Handler": "index.gethtml", "Runtime": "nodejs12.x" + }, + "Type": { + "AWS::Serverless::Function": "invalid_field" } }, "FunctionValid": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -31,13 +30,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "FunctionValidRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -50,7 +48,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -61,7 +60,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3.json b/tests/translator/output/aws-cn/s3.json index be472d5649..4664fdb3b6 100644 --- a/tests/translator/output/aws-cn/s3.json +++ b/tests/translator/output/aws-cn/s3.json @@ -1,89 +1,91 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_create_remove.json b/tests/translator/output/aws-cn/s3_create_remove.json index 0c2833cd49..f323a82fef 100644 --- a/tests/translator/output/aws-cn/s3_create_remove.json +++ b/tests/translator/output/aws-cn/s3_create_remove.json @@ -1,106 +1,110 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": "BucketNameParameter", "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" - }, + } + }, { + "Event": "s3:ObjectRemoved:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectRemoved:*" + } } ] - }, - "BucketName": "BucketNameParameter", - "BucketEncryption": { - "ServerSideEncryptionConfiguration": [{ - "ServerSideEncryptionByDefault": { - "SSEAlgorithm": "AES256" - } - }] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_existing_lambda_notification_configuration.json b/tests/translator/output/aws-cn/s3_existing_lambda_notification_configuration.json index be472d5649..4664fdb3b6 100644 --- a/tests/translator/output/aws-cn/s3_existing_lambda_notification_configuration.json +++ b/tests/translator/output/aws-cn/s3_existing_lambda_notification_configuration.json @@ -1,89 +1,91 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json b/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json index 65d2709c84..2eaf9efe59 100644 --- a/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json +++ b/tests/translator/output/aws-cn/s3_existing_other_notification_configuration.json @@ -1,97 +1,97 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } - ], + ], "TopicConfigurations": [ { - "Topic": "my-super-awesome-topic", - "Event": "s3:ObjectRemoved:*" + "Event": "s3:ObjectRemoved:*", + "Topic": "my-super-awesome-topic" } ] } - }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_filter.json b/tests/translator/output/aws-cn/s3_filter.json index b9c128d6d0..4467343f1e 100644 --- a/tests/translator/output/aws-cn/s3_filter.json +++ b/tests/translator/output/aws-cn/s3_filter.json @@ -1,99 +1,101 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectCreated:*", "Filter": { "S3Key": { "Rules": [ { - "Name": "name", + "Name": "name", "Value": "value" } ] } - }, - "Event": "s3:ObjectCreated:*" + }, + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_intrinsics.json b/tests/translator/output/aws-cn/s3_intrinsics.json index 834251134c..f9dc7bba1a 100644 --- a/tests/translator/output/aws-cn/s3_intrinsics.json +++ b/tests/translator/output/aws-cn/s3_intrinsics.json @@ -15,17 +15,14 @@ }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectCreated:*", "Filter": { "Fn::If": [ "MyCondition", @@ -51,20 +48,57 @@ } ] }, - "Event": "s3:ObjectCreated:*" + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } } ] } }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -77,54 +111,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/s3_multiple_events_same_bucket.json b/tests/translator/output/aws-cn/s3_multiple_events_same_bucket.json index 0c604138ed..1cdb9dcb8d 100644 --- a/tests/translator/output/aws-cn/s3_multiple_events_same_bucket.json +++ b/tests/translator/output/aws-cn/s3_multiple_events_same_bucket.json @@ -1,121 +1,124 @@ { "Resources": { - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ThumbnailFunctionImageBucketCreatesPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketDeletesPermission", "ThumbnailFunctionImageBucketCreatesPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketDeletesPermission", + "ThumbnailFunctionImageBucketCreatesPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectRemoved:*", "Filter": { "S3Key": { "Rules": [ { - "Name": "suffix", + "Name": "suffix", "Value": ".jpg" } ] } - }, - "Event": "s3:ObjectRemoved:*" - }, + }, + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } + }, { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionImageBucketDeletesPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, + }, + "Type": "AWS::S3::Bucket" + }, "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", + }, + "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ - "ThumbnailFunctionRole", + "ThumbnailFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketCreatesPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionImageBucketDeletesPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_multiple_functions.json b/tests/translator/output/aws-cn/s3_multiple_functions.json index e1ba64e229..39eb0e8852 100644 --- a/tests/translator/output/aws-cn/s3_multiple_functions.json +++ b/tests/translator/output/aws-cn/s3_multiple_functions.json @@ -1,99 +1,44 @@ { "Resources": { - "FunctionOneRole": { - "Type": "AWS::IAM::Role", + "FunctionOne": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "FunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "FunctionTwoImageBucketPermission": { - "Type": "AWS::Lambda::Permission", + "FunctionOneImageBucketPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, "FunctionName": { - "Ref": "FunctionTwo" - }, - "Principal": "s3.amazonaws.com" - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "FunctionTwo", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - }, - { - "Function": { - "Fn::GetAtt": [ - "FunctionOne", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] + "Ref": "FunctionOne" }, - "PublicAccessBlockConfiguration": { - "BlockPublicAcls": true, - "BlockPublicPolicy": true, - "IgnorePublicAcls": true, - "RestrictPublicBuckets": true + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" } }, - "DependsOn": [ - "FunctionOneImageBucketPermission", - "FunctionTwoImageBucketPermission" - ] + "Type": "AWS::Lambda::Permission" }, - "FunctionTwoRole": { - "Type": "AWS::IAM::Role", + "FunctionOneRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -106,25 +51,22 @@ ] } } - ] - } - } - }, - "FunctionOneImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "FunctionOne" + ], + "Version": "2012-10-17" }, - "Principal": "s3.amazonaws.com" - } + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "FunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -140,34 +82,92 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionOne": { - "Type": "AWS::Lambda::Function", + "FunctionTwoImageBucketPermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "FunctionTwo" }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "FunctionOneRole", - "Arn" - ] + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionTwoRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "FunctionOneImageBucketPermission", + "FunctionTwoImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionTwo", + "Arn" + ] + } + }, + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionOne", + "Arn" + ] + } + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + } + }, + "Type": "AWS::S3::Bucket" } } } diff --git a/tests/translator/output/aws-cn/s3_with_condition.json b/tests/translator/output/aws-cn/s3_with_condition.json index 7c90662b99..ef09e27f20 100644 --- a/tests/translator/output/aws-cn/s3_with_condition.json +++ b/tests/translator/output/aws-cn/s3_with_condition.json @@ -2,120 +2,120 @@ "Conditions": { "MyCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { "Fn::If": [ - "MyCondition", + "MyCondition", { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" - }, + } + }, { "Ref": "AWS::NoValue" } ] } ] - }, + }, "Tags": [ { + "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission", "Value": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Ref": "ThumbnailFunctionImageBucketPermission" - }, + }, "no dependency" ] - }, - "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission" + } } ] - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Condition": "MyCondition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "MyCondition" - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - }, - "Condition": "MyCondition" - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "MyCondition" + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/s3_with_dependsOn.json b/tests/translator/output/aws-cn/s3_with_dependsOn.json index b2d321a04c..b05eac62e2 100644 --- a/tests/translator/output/aws-cn/s3_with_dependsOn.json +++ b/tests/translator/output/aws-cn/s3_with_dependsOn.json @@ -1,10 +1,6 @@ { "Resources": { - "Topic": { - "Type": "AWS::SNS::Topic" - }, "Images": { - "Type": "AWS::S3::Bucket", "DependsOn": [ "ThumbnailFunctionImageBucketPermission", "Topic" @@ -13,83 +9,87 @@ "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "Topic": { + "Type": "AWS::SNS::Topic" } } } diff --git a/tests/translator/output/aws-cn/self_managed_kafka_with_intrinsics.json b/tests/translator/output/aws-cn/self_managed_kafka_with_intrinsics.json index 7084bd91b3..77e0f8f568 100644 --- a/tests/translator/output/aws-cn/self_managed_kafka_with_intrinsics.json +++ b/tests/translator/output/aws-cn/self_managed_kafka_with_intrinsics.json @@ -1,38 +1,28 @@ { "Parameters": { "BatchSizeValue": { - "Type": "Number", - "Default": 100 + "Default": 100, + "Type": "Number" }, - "EnableValue": { - "Type": "String", - "Default": true + "ConsumerGroupValue": { + "Default": "consumergroup1", + "Type": "String" }, - "TopicsValue": { - "Type": "CommaDelimitedList", - "Default": "Topic" + "EnableValue": { + "Default": true, + "Type": "String" }, "KafkaBootstrapServersValue": { - "Type": "CommaDelimitedList", - "Default": "abc.xyz.com:9092,123.45.67.89:9096" + "Default": "abc.xyz.com:9092,123.45.67.89:9096", + "Type": "CommaDelimitedList" }, - "ConsumerGroupValue": { - "Type": "String", - "Default": "consumergroup1" + "TopicsValue": { + "Default": "Topic", + "Type": "CommaDelimitedList" } }, "Resources": { - "KafkaUserSecret": { - "Type": "AWS::SecretsManager::Secret", - "Properties": { - "Name": "KafkaUserPassword", - "SecretString": { - "Fn::Sub": "{\"username\":\"testBrokerUser\",\"password\":\"testBrokerPassword\"}" - } - } - }, "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -52,13 +42,57 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "BatchSize": { + "Ref": "BatchSizeValue" + }, + "Enabled": { + "Ref": "EnableValue" + }, + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": { + "Ref": "KafkaBootstrapServersValue" + } + } + }, + "SelfManagedKafkaEventSourceConfig": { + "ConsumerGroupId": { + "Ref": "ConsumerGroupValue" + } + }, + "SourceAccessConfigurations": [ + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + }, + { + "Type": "BASIC_AUTH", + "URI": { + "Ref": "KafkaUserSecret" + } + } + ], + "Topics": { + "Ref": "TopicsValue" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -71,7 +105,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -113,52 +148,17 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", + "KafkaUserSecret": { "Properties": { - "BatchSize": { - "Ref": "BatchSizeValue" - }, - "Enabled": { - "Ref": "EnableValue" - }, - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": { - "Ref": "TopicsValue" - }, - "SourceAccessConfigurations": [ - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - }, - { - "Type": "BASIC_AUTH", - "URI": { - "Ref": "KafkaUserSecret" - } - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": { - "Ref": "KafkaBootstrapServersValue" - } - } - }, - "SelfManagedKafkaEventSourceConfig": { - "ConsumerGroupId": { - "Ref": "ConsumerGroupValue" - } + "Name": "KafkaUserPassword", + "SecretString": { + "Fn::Sub": "{\"username\":\"testBrokerUser\",\"password\":\"testBrokerPassword\"}" } - } + }, + "Type": "AWS::SecretsManager::Secret" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json b/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json index cd79e4bc19..07b3755cbe 100644 --- a/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json +++ b/tests/translator/output/aws-cn/simple_table_ref_parameter_intrinsic.json @@ -1,5 +1,9 @@ { "Parameters": { + "EnableSSE": { + "Default": true, + "Type": "String" + }, "ReadCapacity": { "Default": 15, "Type": "Number" @@ -7,42 +11,38 @@ "WriteCapacity": { "Default": 15, "Type": "Number" - }, - "EnableSSE": { - "Default": true, - "Type": "String" } }, "Resources": { "MinimalTableRefParamLongForm": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "ProvisionedThroughput": { - "WriteCapacityUnits": { - "Ref": "WriteCapacity" - }, - "ReadCapacityUnits": { - "Ref": "ReadCapacity" - } - }, "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": { + "Ref": "ReadCapacity" + }, + "WriteCapacityUnits": { + "Ref": "WriteCapacity" + } + }, "SSESpecification": { "SSEEnabled": { "Ref": "EnableSSE" } - }, - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] - } + } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/simple_table_with_extra_tags.json b/tests/translator/output/aws-cn/simple_table_with_extra_tags.json index a02e088cd8..55ad2e3e58 100644 --- a/tests/translator/output/aws-cn/simple_table_with_extra_tags.json +++ b/tests/translator/output/aws-cn/simple_table_with_extra_tags.json @@ -7,42 +7,42 @@ }, "Resources": { "MinimalTableWithTags": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ], "Tags": [ { - "Value": "TagValue1", - "Key": "TagKey1" + "Key": "TagKey1", + "Value": "TagValue1" }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/simple_table_with_table_name.json b/tests/translator/output/aws-cn/simple_table_with_table_name.json index f70cdcc4e4..3778fe19f3 100644 --- a/tests/translator/output/aws-cn/simple_table_with_table_name.json +++ b/tests/translator/output/aws-cn/simple_table_with_table_name.json @@ -1,71 +1,71 @@ { "Parameters": { "MySimpleTableParameter": { - "Default": "TableName", + "Default": "TableName", "Type": "String" } }, "Resources": { - "MinimalTableWithTableName": { - "Type": "AWS::DynamoDB::Table", + "MinimalTableWithRefTableName": { "Properties": { - "TableName": "MySimpleTable", - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } - }, - "MinimalTableWithRefTableName": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "TableName": { "Ref": "MySimpleTableParameter" - }, - "BillingMode": "PAY_PER_REQUEST", + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTableWithSubTableName": { + "Properties": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } - }, - "MinimalTableWithSubTableName": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "TableName": { "Fn::Sub": "${AWS::StackName}MySimpleTable" - }, - "BillingMode": "PAY_PER_REQUEST", + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTableWithTableName": { + "Properties": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } + ], + "TableName": "MySimpleTable" + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/simpletable.json b/tests/translator/output/aws-cn/simpletable.json index c59f7a660d..7176a71daf 100644 --- a/tests/translator/output/aws-cn/simpletable.json +++ b/tests/translator/output/aws-cn/simpletable.json @@ -1,43 +1,43 @@ { "Resources": { - "MinimalTable": { - "Type": "AWS::DynamoDB::Table", + "CompleteTable": { "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { - "AttributeName": "id", - "AttributeType": "S" + "AttributeName": "member-number", + "AttributeType": "N" } - ], + ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "member-number", + "KeyType": "HASH" } - ] - } - }, - "CompleteTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "ProvisionedThroughput": { - "WriteCapacityUnits": 10, - "ReadCapacityUnits": 20 - }, + "ReadCapacityUnits": 20, + "WriteCapacityUnits": 10 + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTable": { + "Properties": { "AttributeDefinitions": [ { - "AttributeName": "member-number", - "AttributeType": "N" + "AttributeName": "id", + "AttributeType": "S" } - ], + ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "member-number" + "AttributeName": "id", + "KeyType": "HASH" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/simpletable_with_sse.json b/tests/translator/output/aws-cn/simpletable_with_sse.json index ab4c3d3f59..13df879afc 100644 --- a/tests/translator/output/aws-cn/simpletable_with_sse.json +++ b/tests/translator/output/aws-cn/simpletable_with_sse.json @@ -1,25 +1,25 @@ { - "Resources": { - "TableWithSSE": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "SSESpecification": { - "SSEEnabled": true - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] + "Resources": { + "TableWithSSE": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "SSESpecification": { + "SSEEnabled": true } - } + }, + "Type": "AWS::DynamoDB::Table" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/sns.json b/tests/translator/output/aws-cn/sns.json index 236d8baef2..c61f05bd09 100644 --- a/tests/translator/output/aws-cn/sns.json +++ b/tests/translator/output/aws-cn/sns.json @@ -2,87 +2,87 @@ "Resources": { "Notifications": { "Type": "AWS::SNS::Topic" - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "Notifications" - } - } - }, + }, "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", + }, + "Handler": "index.save_notification", "Role": { "Fn::GetAtt": [ - "SaveNotificationFunctionRole", + "SaveNotificationFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "SaveNotificationFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/sns_existing_other_subscription.json b/tests/translator/output/aws-cn/sns_existing_other_subscription.json index 98ad0f9fa0..0abcf4863c 100644 --- a/tests/translator/output/aws-cn/sns_existing_other_subscription.json +++ b/tests/translator/output/aws-cn/sns_existing_other_subscription.json @@ -1,96 +1,96 @@ { "Resources": { "Notifications": { - "Type": "AWS::SNS::Topic", "Properties": { "Subscription": [ { - "Endpoint": "my-queue-arn", + "Endpoint": "my-queue-arn", "Protocol": "sqs" } ] - } - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "Notifications" - } - } - }, + }, + "Type": "AWS::SNS::Topic" + }, "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", + }, + "Handler": "index.save_notification", "Role": { "Fn::GetAtt": [ - "SaveNotificationFunctionRole", + "SaveNotificationFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "SaveNotificationFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/sns_existing_sqs.json b/tests/translator/output/aws-cn/sns_existing_sqs.json index 326c6baba5..8e46790c58 100644 --- a/tests/translator/output/aws-cn/sns_existing_sqs.json +++ b/tests/translator/output/aws-cn/sns_existing_sqs.json @@ -1,31 +1,11 @@ { "Resources": { - "Queue": { - "Type": "AWS::SQS::Queue" - }, - "Notifications": { - "Type": "AWS::SNS::Topic" - }, "NotificationA": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - { - "Ref": "Queue" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - }, - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -33,15 +13,63 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + } } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "Queue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "Notifications": { + "Type": "AWS::SNS::Topic" + }, + "Queue": { + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + }, "FilterPolicy": { "price_usd": [ { @@ -55,23 +83,32 @@ "example_corp" ] }, - "Endpoint": { + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 8, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "Queue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -84,7 +121,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -92,50 +130,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 8, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/sns_intrinsics.json b/tests/translator/output/aws-cn/sns_intrinsics.json index b65f7eddfa..8807e7981a 100644 --- a/tests/translator/output/aws-cn/sns_intrinsics.json +++ b/tests/translator/output/aws-cn/sns_intrinsics.json @@ -17,46 +17,37 @@ "Notifications": { "Type": "AWS::SNS::Topic" }, - "SaveNotificationFunctionNotificationTopicQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "SaveNotificationFunctionNotificationTopicQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "SaveNotificationFunction": { "Properties": { - "Queues": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Ref": "SaveNotificationFunctionNotificationTopicQueue" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + }, "FilterPolicy": { "Fn::If": [ "MyCondition", @@ -82,26 +73,72 @@ } ] }, + "Protocol": "sqs", "Region": { "Ref": "SnsRegion" }, - "Endpoint": { + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "SaveNotificationFunctionNotificationTopicQueue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SaveNotificationFunctionNotificationTopicQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunctionNotificationTopicQueuePolicy": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } + } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "SaveNotificationFunctionNotificationTopicQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -114,7 +151,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -122,50 +160,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/sns_outside_sqs.json b/tests/translator/output/aws-cn/sns_outside_sqs.json index 624867e0a5..64f9208d51 100644 --- a/tests/translator/output/aws-cn/sns_outside_sqs.json +++ b/tests/translator/output/aws-cn/sns_outside_sqs.json @@ -1,18 +1,11 @@ { "Resources": { "NotificationB": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue" - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": "arn:aws:sqs:us-east-1:123456789012:MyQueue", - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -20,18 +13,48 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": "arn:aws:sqs:us-east-1:123456789012:MyQueue" } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Queues": [ + "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue" + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, "Notifications": { "Type": "AWS::SNS::Topic" }, + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": "arn:aws:sqs:us-east-1:123456789012:MyQueue", "FilterPolicy": { "price_usd": [ { @@ -45,18 +68,27 @@ "example_corp" ] }, - "Endpoint": "arn:aws:sqs:us-east-1:123456789012:MyQueue", "Protocol": "sqs", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 8, + "Enabled": true, + "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:MyQueue", + "FunctionName": { + "Ref": "SaveNotificationFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -69,7 +101,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -77,45 +110,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 8, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:MyQueue" - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/sns_sqs.json b/tests/translator/output/aws-cn/sns_sqs.json index 90961ae75e..34fa04b7b3 100644 --- a/tests/translator/output/aws-cn/sns_sqs.json +++ b/tests/translator/output/aws-cn/sns_sqs.json @@ -2,141 +2,141 @@ "Resources": { "Notifications": { "Type": "AWS::SNS::Topic" - }, - "SaveNotificationFunctionNotificationTopicQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "SaveNotificationFunctionNotificationTopicQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + }, + "SaveNotificationFunction": { "Properties": { - "Queues": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Ref": "SaveNotificationFunctionNotificationTopicQueue" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + }, "FilterPolicy": { "price_usd": [ { "numeric": [ - ">=", + ">=", 100 ] } - ], + ], "store": [ "example_corp" ] - }, - "Endpoint": { + }, + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", + "SaveNotificationFunctionNotificationTopicQueue", "Arn" ] - }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + }, + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SaveNotificationFunctionNotificationTopicQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunctionNotificationTopicQueuePolicy": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } + } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Queues": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "SaveNotificationFunctionNotificationTopicQueue" } - ], + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "SaveNotificationFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, - "EventSourceArn": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "FunctionName": { - "Ref": "SaveNotificationFunction" - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/sns_topic_outside_template.json b/tests/translator/output/aws-cn/sns_topic_outside_template.json index 60e185e066..3d721dab35 100644 --- a/tests/translator/output/aws-cn/sns_topic_outside_template.json +++ b/tests/translator/output/aws-cn/sns_topic_outside_template.json @@ -3,88 +3,88 @@ "SNSTopicArn": { "Type": "String" } - }, + }, "Resources": { + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "SNSTopicArn" } - } - }, + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "SNSTopicArn" + } + }, + "Type": "AWS::Lambda::Permission" + }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "SNSTopicArn" - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/sqs.json b/tests/translator/output/aws-cn/sqs.json index cad7b2248b..eab3f84f60 100644 --- a/tests/translator/output/aws-cn/sqs.json +++ b/tests/translator/output/aws-cn/sqs.json @@ -1,36 +1,6 @@ { "Resources": { - "SQSFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } - }, "SQSFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -44,14 +14,16 @@ ] }, "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "SQSFunctionMySqsQueue": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 10, "Enabled": false, @@ -59,7 +31,39 @@ "FunctionName": { "Ref": "SQSFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SQSFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_api_auth_default_scopes.json b/tests/translator/output/aws-cn/state_machine_with_api_auth_default_scopes.json index 6a466f04a9..aeb314cddf 100644 --- a/tests/translator/output/aws-cn/state_machine_with_api_auth_default_scopes.json +++ b/tests/translator/output/aws-cn/state_machine_with_api_auth_default_scopes.json @@ -1,733 +1,733 @@ { - "Resources": { - "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/cognitowithauthnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoWithAuthNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "NONE": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoAuthorizerWithDefaultScopesRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoAuthorizerScopesOverwrittenRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesWithOverwrittenRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [ - "overwritten.read", - "overwritten.write" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:2" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } + "Resources": { + "MyApiWithCognitoAuth": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuthWithDefaultScopes": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:2" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyDefaultCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } } - }, - "MyStateMachineCognitoWithAuthNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoWithAuthNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/cognitoauthorizercopesoverwritten": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoAuthorizerScopesOverwrittenRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultScopesNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoAuthorizerWithDefaultScopesRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultScopesWithOverwrittenRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesWithOverwrittenRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [ + "overwritten.read", + "overwritten.write" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesWithOverwrittenRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoWithAuthNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment57b57dfc88" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeployment57b57dfc88": { + "Properties": { + "Description": "RestApi deployment id: 57b57dfc88b1b438a0437eadd869d77e938eedb6", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment57b57dfc88" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyStateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyStateMachineCognitoAuthorizerScopesOverwrittenRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiWithCognitoAuthDeployment57b57dfc88": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 57b57dfc88b1b438a0437eadd869d77e938eedb6" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoAuthorizerScopesOverwrittenRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoAuthorizerWithDefaultScopesRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoAuthorizerWithDefaultScopesRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyStateMachineCognitoAuthorizerWithDefaultScopesRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoAuthorizerWithDefaultScopesRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineCognitoAuthorizerScopesOverwrittenRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoAuthorizerScopesOverwrittenRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesWithOverwrittenRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "MyStateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesWithOverwrittenRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoWithAuthNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoWithAuthNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_api_authorizer.json b/tests/translator/output/aws-cn/state_machine_with_api_authorizer.json index 859dea4893..7eca5da933 100644 --- a/tests/translator/output/aws-cn/state_machine_with_api_authorizer.json +++ b/tests/translator/output/aws-cn/state_machine_with_api_authorizer.json @@ -1,384 +1,384 @@ { - "Resources": { - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startWithLambdaToken": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaTokenAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" + "StateMachineWithLambdaTokenAuthRole", + "Arn" ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaaffc688ce" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startNoAuth": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithNoAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "StateMachineWithLambdaTokenAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + }, + "securityDefinitions": { + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineWithLambdaTokenAuthRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startWithLambdaToken": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaTokenAuthRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaTokenAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, - "x-amazon-apigateway-authtype": "custom" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment2d6a709a2a": { + "Properties": { + "Description": "RestApi deployment id: 2d6a709a2a2b67ee19ca14fe4594114921c537d0", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment2d6a709a2a" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startNoAuth": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithNoAuthorizerRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ] - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment2d6a709a2a" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } } - }, - "ServerlessRestApiDeploymentaaffc688ce": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aaffc688ce6d1b26ccd7a90641e103263f6240bb", - "StageName": "Stage" + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaaffc688ce": { + "Properties": { + "Description": "RestApi deployment id: aaffc688ce6d1b26ccd7a90641e103263f6240bb", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaaffc688ce" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - }, - "StateMachineWithNoAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaTokenAuthRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiDeployment2d6a709a2a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 2d6a709a2a2b67ee19ca14fe4594114921c537d0", - "StageName": "Stage" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithLambdaTokenAuthRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithNoAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_api_authorizer_maximum.json b/tests/translator/output/aws-cn/state_machine_with_api_authorizer_maximum.json index 4755fb3169..2702c30ec7 100644 --- a/tests/translator/output/aws-cn/state_machine_with_api_authorizer_maximum.json +++ b/tests/translator/output/aws-cn/state_machine_with_api_authorizer_maximum.json @@ -1,690 +1,690 @@ { - "Resources": { - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "NONE": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithNoAuthorizerRole", + "Arn" ] - } - } - }, - "StateMachineWithLambdaRequestAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithLambdaRequestAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + } + }, + "/users": { + "delete": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" + "StateMachineWithLambdaRequestAuthorizerRole", + "Arn" ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "StateMachineWithDefaultAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithDefaultAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithNoAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "NONE": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/users": { - "put": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithDefaultAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthMultipleUserPools": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "patch": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaTokenAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "delete": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaRequestAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaRequestAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, - "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, - "x-amazon-apigateway-authtype": "custom" - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } + }, + "patch": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithLambdaTokenAuthorizerRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + }, + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthMultipleUserPools": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole", + "Arn" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } + }, + "put": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithDefaultAuthorizerRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + }, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "Tags": [ + ] + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "__FunctionArn__": "arn:aws" } - ] - } - }, - "StateMachineWithLambdaTokenAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineWithLambdaTokenAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment704a2ea820": { + "Properties": { + "Description": "RestApi deployment id: 704a2ea8202a6b11b22e31524b5e5dfa2b528378", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment704a2ea820" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiDeployment704a2ea820": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 704a2ea8202a6b11b22e31524b5e5dfa2b528378", - "StageName": "Stage" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithCognitoMultipleUserPoolsAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithDefaultAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment704a2ea820" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithDefaultAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaRequestAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithCognitoMultipleUserPoolsAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaRequestAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaTokenAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "StateMachineWithNoAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaTokenAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithNoAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_api_resource_policy.json b/tests/translator/output/aws-cn/state_machine_with_api_resource_policy.json index f9b4100a56..42a3dc5da6 100644 --- a/tests/translator/output/aws-cn/state_machine_with_api_resource_policy.json +++ b/tests/translator/output/aws-cn/state_machine_with_api_resource_policy.json @@ -1,482 +1,482 @@ { - "Resources": { - "MyStateMachineGetHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineGetHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/one": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineGetHtmlRole", + "Arn" ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineGetHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachinePutHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachinePostHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Allow", - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "NotIpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Allow", - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "NotIpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - } - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment17065a95ba" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "MyStateMachinePutHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachinePutHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/three": { + "put": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachinePutHtmlRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/two": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachinePostHtmlRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRole", - "Arn" + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "IpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } + ] + } ] + }, + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "IpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + } + ], + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment17065a95ba": { + "Properties": { + "Description": "RestApi deployment id: 17065a95bac1ac0e3dc22fef2ff7aa228539b1d2", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment17065a95ba" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyStateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyStateMachineGetHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "ExplicitApiDeployment17065a95ba": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 17065a95bac1ac0e3dc22fef2ff7aa228539b1d2", - "StageName": "Stage" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineGetHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachinePostHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "MyStateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachinePostHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachinePutHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyStateMachinePostHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachinePostHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachinePutHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_condition.json b/tests/translator/output/aws-cn/state_machine_with_condition.json index 7d67abe1a4..f723ffa179 100644 --- a/tests/translator/output/aws-cn/state_machine_with_condition.json +++ b/tests/translator/output/aws-cn/state_machine_with_condition.json @@ -2,30 +2,30 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "test", + "test", "test" ] } - }, + }, "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "Condition": "TestCondition", "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachine", "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachine", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - }, - "Condition": "TestCondition" + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_condition_and_events.json b/tests/translator/output/aws-cn/state_machine_with_condition_and_events.json index 8e0a7a0ab3..c706371a84 100644 --- a/tests/translator/output/aws-cn/state_machine_with_condition_and_events.json +++ b/tests/translator/output/aws-cn/state_machine_with_condition_and_events.json @@ -1,305 +1,305 @@ { - "Conditions": { - "TestCondition": { - "Fn::Equals": [ - "test", - "test" - ] - } - }, - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "test", + "test" + ] + } + }, + "Resources": { + "ServerlessRestApi": { + "Condition": "TestCondition", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "Fn::If": [ + "TestCondition", + { + "post": { + "Fn::If": [ + "TestCondition", + { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::If": [ + "TestCondition", + { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + }, + { + "Ref": "AWS::NoValue" + } + ] + } } + }, + { + "Ref": "AWS::NoValue" + } ] + } + }, + { + "Ref": "AWS::NoValue" } - }, - "Condition": "TestCondition" - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachine", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ] + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaeae651245": { + "Condition": "TestCondition", + "Properties": { + "Description": "RestApi deployment id: aeae651245fe7d417a17f2bea50b255f2727e2b8", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "TestCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaeae651245" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Condition": "TestCondition", + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineCWEvent": { + "Condition": "TestCondition", + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] + } + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineCWEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" ] - }, - "Condition": "TestCondition" - }, - "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaeae651245" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "TestCondition" - }, - "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } - ], - "Name": "TestSchedule" - }, - "Condition": "TestCondition" - }, - "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineMyApiEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] - }, - "Condition": "TestCondition" - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "Fn::If": [ - "TestCondition", - { - "post": { - "Fn::If": [ - "TestCondition", - { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::If": [ - "TestCondition", - { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - }, - "ServerlessRestApiDeploymentaeae651245": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aeae651245fe7d417a17f2bea50b255f2727e2b8", - "StageName": "Stage" - }, - "Condition": "TestCondition" - }, - "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineScheduleEvent": { + "Condition": "TestCondition", + "Properties": { + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" + ] + } + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineScheduleEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_cwe.json b/tests/translator/output/aws-cn/state_machine_with_cwe.json index 95940a3534..fb1f076239 100644 --- a/tests/translator/output/aws-cn/state_machine_with_cwe.json +++ b/tests/translator/output/aws-cn/state_machine_with_cwe.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,76 +24,61 @@ "terminated" ] } - }, + }, "State": "ENABLED", "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_definition_S3_object.json b/tests/translator/output/aws-cn/state_machine_with_definition_S3_object.json index 81caf3cfe2..eb0eed7d81 100644 --- a/tests/translator/output/aws-cn/state_machine_with_definition_S3_object.json +++ b/tests/translator/output/aws-cn/state_machine_with_definition_S3_object.json @@ -1,138 +1,138 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "states.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithDefinitionInS3", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithDefinitionInS3", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_definition_S3_string.json b/tests/translator/output/aws-cn/state_machine_with_definition_S3_string.json index 97b28ece42..f525b3d41f 100644 --- a/tests/translator/output/aws-cn/state_machine_with_definition_S3_string.json +++ b/tests/translator/output/aws-cn/state_machine_with_definition_S3_string.json @@ -1,137 +1,137 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "states.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithDefinitionInS3", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithDefinitionInS3", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "Key": "stateMachine:createdBy", + "Value": "SAM" } - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_definition_substitutions.json b/tests/translator/output/aws-cn/state_machine_with_definition_substitutions.json index 0b6ac94f69..97010bde17 100644 --- a/tests/translator/output/aws-cn/state_machine_with_definition_substitutions.json +++ b/tests/translator/output/aws-cn/state_machine_with_definition_substitutions.json @@ -1,13 +1,12 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", @@ -17,65 +16,16 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -88,38 +38,23 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "my_state_var_1": "Pass", - "my_state_var_2": "Task" - }, - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, "DefinitionString": { "Fn::Join": [ "\n", @@ -143,13 +78,78 @@ ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "my_state_var_1": "Pass", + "my_state_var_2": "Task" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_eb_dlq.json b/tests/translator/output/aws-cn/state_machine_with_eb_dlq.json index e49e64256f..24a206c3d4 100644 --- a/tests/translator/output/aws-cn/state_machine_with_eb_dlq.json +++ b/tests/translator/output/aws-cn/state_machine_with_eb_dlq.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,78 +24,63 @@ "terminated" ] } - }, + }, "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "DeadLetterConfig": { + "Arn": "TestDlqArn" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "DeadLetterConfig": { - "Arn": "TestDlqArn" - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_eb_dlq_generated.json b/tests/translator/output/aws-cn/state_machine_with_eb_dlq_generated.json index 7e57f89263..70f2a5724d 100644 --- a/tests/translator/output/aws-cn/state_machine_with_eb_dlq_generated.json +++ b/tests/translator/output/aws-cn/state_machine_with_eb_dlq_generated.json @@ -1,11 +1,22 @@ { "Resources": { - "TestDLQ": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -13,121 +24,110 @@ "terminated" ] } - }, + }, "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, + "Arn": { + "Ref": "StateMachine" + }, "DeadLetterConfig": { "Arn": { "Fn::GetAtt": [ - "TestDLQ", + "TestDLQ", "Arn" ] } - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - { - "Ref": "TestDLQ" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "TestDLQ", - "Arn" - ] - }, - "Effect": "Allow", + "Action": "sqs:SendMessage", "Condition": { "ArnEquals": { "aws:SourceArn": { "Fn::GetAtt": [ - "StateMachineCWEvent", + "StateMachineCWEvent", "Arn" ] } } - }, + }, + "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "TestDLQ", + "Arn" + ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Queues": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Ref": "TestDLQ" } ] - } - }, + }, + "Type": "AWS::SQS::QueuePolicy" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TestDLQ": { + "Properties": {}, + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_eb_retry_policy.json b/tests/translator/output/aws-cn/state_machine_with_eb_retry_policy.json index bff94e177a..18813d71f7 100644 --- a/tests/translator/output/aws-cn/state_machine_with_eb_retry_policy.json +++ b/tests/translator/output/aws-cn/state_machine_with_eb_retry_policy.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,79 +24,64 @@ "terminated" ] } - }, + }, "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", "Arn": { "Ref": "StateMachine" - }, + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 300, + "MaximumEventAgeInSeconds": 300, "MaximumRetryAttempts": 5 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_event_schedule_state.json b/tests/translator/output/aws-cn/state_machine_with_event_schedule_state.json index a38e480ed1..c3b472071f 100644 --- a/tests/translator/output/aws-cn/state_machine_with_event_schedule_state.json +++ b/tests/translator/output/aws-cn/state_machine_with_event_schedule_state.json @@ -1,7 +1,6 @@ { "Resources": { "ScheduledStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -14,10 +13,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "ScheduledStateMachineSchedule1": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -37,13 +36,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule1Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,11 +54,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule1RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -71,13 +69,14 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule1RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ScheduledStateMachineSchedule2": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -99,13 +98,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule2Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -118,11 +116,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule2RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -133,13 +131,14 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule2RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ScheduledStateMachineSchedule3": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -161,13 +160,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule3Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,11 +178,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule3RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -195,10 +193,12 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule3RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-cn/state_machine_with_explicit_api.json b/tests/translator/output/aws-cn/state_machine_with_explicit_api.json index 70ef4676a3..4e1e8c9b24 100644 --- a/tests/translator/output/aws-cn/state_machine_with_explicit_api.json +++ b/tests/translator/output/aws-cn/state_machine_with_explicit_api.json @@ -1,210 +1,210 @@ { - "Resources": { - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ] + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment05bc9f394c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment05bc9f394c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - } - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_express_logging.json b/tests/translator/output/aws-cn/state_machine_with_express_logging.json index 5a5583bf67..663c0a5d72 100644 --- a/tests/translator/output/aws-cn/state_machine_with_express_logging.json +++ b/tests/translator/output/aws-cn/state_machine_with_express_logging.json @@ -1,180 +1,180 @@ { "Resources": { + "ExpressLogGroup": { + "Type": "AWS::Logs::LogGroup" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "ExpressLogGroup", + "Arn" + ] + } + } + } + ], + "IncludeExecutionData": false, + "Level": "FATAL" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStandardStateMachineWithLogging", + "StateMachineType": "EXPRESS", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] - }, - "Effect": "Allow" + } } - ] - } - }, + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + }, { - "PolicyName": "StateMachineRolePolicy1", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", "logs:DescribeLogGroups" - ], + ], + "Effect": "Allow", "Resource": [ "*" - ], - "Effect": "Allow" + ] } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy1" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "ExpressLogGroup": { - "Type": "AWS::Logs::LogGroup" - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStandardStateMachineWithLogging", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "LoggingConfiguration": { - "IncludeExecutionData": false, - "Level": "FATAL", - "Destinations": [ - { - "CloudWatchLogsLogGroup": { - "LogGroupArn": { - "Fn::GetAtt": [ - "ExpressLogGroup", - "Arn" - ] - } - } - } - ] - }, - "StateMachineType": "EXPRESS", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_implicit_api.json b/tests/translator/output/aws-cn/state_machine_with_implicit_api.json index ebb4b1c02c..0b098f32b9 100644 --- a/tests/translator/output/aws-cn/state_machine_with_implicit_api.json +++ b/tests/translator/output/aws-cn/state_machine_with_implicit_api.json @@ -1,210 +1,210 @@ { - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment05bc9f394c" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + "StateMachineMyApiEventRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment05bc9f394c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_implicit_api_globals.json b/tests/translator/output/aws-cn/state_machine_with_implicit_api_globals.json index c28b4704f7..eaf74275c3 100644 --- a/tests/translator/output/aws-cn/state_machine_with_implicit_api_globals.json +++ b/tests/translator/output/aws-cn/state_machine_with_implicit_api_globals.json @@ -1,232 +1,232 @@ { - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + "StateMachineMyApiEventRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment1f01b589d4" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment1f01b589d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 1f01b589d4e226c84a3e14ca738b5d060e7b611a", - "StageName": "Stage" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "Tags": [ + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "12345" + ] + }, + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/startMyExecution", { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "__Stage__": "Prod" } + ] + } + ] + }, + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment1f01b589d4": { + "Properties": { + "Description": "RestApi deployment id: 1f01b589d4e226c84a3e14ca738b5d060e7b611a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment1f01b589d4" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/startMyExecution", - { - "__Stage__": "Prod" - } - ] - } - ], - "Effect": "Deny", - "Principal": { - "AWS": [ - "12345" - ] - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/state_machine_with_inline_definition.json b/tests/translator/output/aws-cn/state_machine_with_inline_definition.json index 722bc9ec70..5564d443ee 100644 --- a/tests/translator/output/aws-cn/state_machine_with_inline_definition.json +++ b/tests/translator/output/aws-cn/state_machine_with_inline_definition.json @@ -1,89 +1,89 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyBasicStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Deny" + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyBasicStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_inline_definition_intrinsics.json b/tests/translator/output/aws-cn/state_machine_with_inline_definition_intrinsics.json index 0237cf961f..0c058cdec0 100644 --- a/tests/translator/output/aws-cn/state_machine_with_inline_definition_intrinsics.json +++ b/tests/translator/output/aws-cn/state_machine_with_inline_definition_intrinsics.json @@ -1,82 +1,32 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "MyFunctionRole", "Arn" ] }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,21 +39,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ @@ -128,12 +79,14 @@ ] ] }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, "RoleArn": { "Fn::GetAtt": [ "StateMachineRole", @@ -141,16 +94,63 @@ ] }, "StateMachineName": "MyBasicStateMachine", - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StateMachineType": "STANDARD" - } + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_inline_policies.json b/tests/translator/output/aws-cn/state_machine_with_inline_policies.json index 0237cf961f..0c058cdec0 100644 --- a/tests/translator/output/aws-cn/state_machine_with_inline_policies.json +++ b/tests/translator/output/aws-cn/state_machine_with_inline_policies.json @@ -1,82 +1,32 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "MyFunctionRole", "Arn" ] }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,21 +39,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ @@ -128,12 +79,14 @@ ] ] }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, "RoleArn": { "Fn::GetAtt": [ "StateMachineRole", @@ -141,16 +94,63 @@ ] }, "StateMachineName": "MyBasicStateMachine", - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StateMachineType": "STANDARD" - } + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_managed_policy.json b/tests/translator/output/aws-cn/state_machine_with_managed_policy.json index be6090ce90..77683bd8b1 100644 --- a/tests/translator/output/aws-cn/state_machine_with_managed_policy.json +++ b/tests/translator/output/aws-cn/state_machine_with_managed_policy.json @@ -1,57 +1,57 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithManagedPolicy", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/AmazonDynamoDBFullAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithManagedPolicy", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_null_events.json b/tests/translator/output/aws-cn/state_machine_with_null_events.json index eb62a90415..772ee4032d 100644 --- a/tests/translator/output/aws-cn/state_machine_with_null_events.json +++ b/tests/translator/output/aws-cn/state_machine_with_null_events.json @@ -1,7 +1,6 @@ { "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -14,7 +13,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_permissions_boundary.json b/tests/translator/output/aws-cn/state_machine_with_permissions_boundary.json index 645e7d5a30..cb2add7f0f 100644 --- a/tests/translator/output/aws-cn/state_machine_with_permissions_boundary.json +++ b/tests/translator/output/aws-cn/state_machine_with_permissions_boundary.json @@ -1,114 +1,167 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Policies": [ + }, + "Runtime": "python2.7", + "Tags": [ { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "apigateway.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment05bc9f394c" - }, + }, "RestApiId": { "Ref": "ServerlessRestApi" - }, + }, "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -116,265 +169,212 @@ "terminated" ] } - }, + }, "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineCWEventRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "events.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" } ] - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineMyApiEventRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" } } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { "functionName": { "Ref": "MyFunction" } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "StateMachineRolePolicy0" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineScheduleEvent": { "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Policies": [ + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" ] } } - ], + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineScheduleEventRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } - ], - "Name": "TestSchedule" - } - }, - "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Policies": [ { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { - "Action": "states:StartExecution", + "Action": "states:StartExecution", + "Effect": "Allow", "Resource": { "Ref": "StateMachine" - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_role.json b/tests/translator/output/aws-cn/state_machine_with_role.json index 0db8c03ab0..7b3b87fb4b 100644 --- a/tests/translator/output/aws-cn/state_machine_with_role.json +++ b/tests/translator/output/aws-cn/state_machine_with_role.json @@ -1,22 +1,22 @@ { "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachineWithRole", "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "my-state-machine.asl.json" - }, - "StateMachineType": "STANDARD", + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithRole", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_sam_policy_templates.json b/tests/translator/output/aws-cn/state_machine_with_sam_policy_templates.json index 17fb1640d1..afe1e26892 100644 --- a/tests/translator/output/aws-cn/state_machine_with_sam_policy_templates.json +++ b/tests/translator/output/aws-cn/state_machine_with_sam_policy_templates.json @@ -1,40 +1,7 @@ { "Resources": { - "ResolverLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "resolver.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "resolver.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ResolverLambdaRole", - "Arn" - ] - }, - "Runtime": "python3.8", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, "NestedWorkflow": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "StarterLambda", - "Arn" - ] - } - }, - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", "DefinitionString": { "Fn::Join": [ "\n", @@ -60,67 +27,49 @@ ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "StarterLambda", + "Arn" + ] + } + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, - "StarterLambda": { - "Type": "AWS::Lambda::Function", + "OutputStore": { "Properties": { - "Handler": "starter.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "starter.zip" - }, - "Role": { - "Fn::GetAtt": [ - "StarterLambdaRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ + "AttributeDefinitions": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "AttributeName": "id", + "AttributeType": "S" } - ] - } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "TableName": "MySimpleTable" + }, + "Type": "AWS::DynamoDB::Table" + }, + "ProcessingQueue": { + "Type": "AWS::SQS::Queue" }, "ProcessingWorkflow": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_4": { - "Ref": "NestedWorkflow" - }, - "definition_substitution_5": { - "Ref": "OutputStore" - }, - "definition_substitution_2": { - "Ref": "ResolverLambda" - }, - "definition_substitution_3": { - "Ref": "ProcessingQueue" - }, - "definition_substitution_1": { - "Fn::GetAtt": [ - "StarterLambda", - "Arn" - ] - } - }, - "RoleArn": { - "Fn::GetAtt": [ - "ProcessingWorkflowRole", - "Arn" - ] - }, "DefinitionString": { "Fn::Join": [ "\n", @@ -231,50 +180,45 @@ ] ] }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "StarterLambda", + "Arn" + ] + }, + "definition_substitution_2": { + "Ref": "ResolverLambda" + }, + "definition_substitution_3": { + "Ref": "ProcessingQueue" + }, + "definition_substitution_4": { + "Ref": "NestedWorkflow" + }, + "definition_substitution_5": { + "Ref": "OutputStore" } - ] - } - }, - "StarterLambdaRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + }, + "RoleArn": { + "Fn::GetAtt": [ + "ProcessingWorkflowRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "ProcessingWorkflowRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -287,18 +231,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "ProcessingWorkflowRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -308,20 +253,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy0" }, { - "PolicyName": "ProcessingWorkflowRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -334,20 +279,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy1" }, { - "PolicyName": "ProcessingWorkflowRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -357,20 +302,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy2" }, { - "PolicyName": "ProcessingWorkflowRolePolicy3", "PolicyDocument": { "Statement": [ { "Action": [ "states:StartExecution" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", @@ -383,14 +328,13 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy3" }, { - "PolicyName": "ProcessingWorkflowRolePolicy4", "PolicyDocument": { "Statement": [ { @@ -399,6 +343,7 @@ "dynamodb:UpdateItem", "dynamodb:BatchWriteItem" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -420,48 +365,101 @@ } ] } - ], - "Effect": "Allow" + ] } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy4" } ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "OutputStore": { - "Type": "AWS::DynamoDB::Table", + "ResolverLambda": { "Properties": { - "KeySchema": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "resolver.zip" + }, + "Handler": "resolver.handler", + "Role": { + "Fn::GetAtt": [ + "ResolverLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.8", + "Tags": [ { - "KeyType": "HASH", - "AttributeName": "id" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ResolverLambdaRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "TableName": "MySimpleTable", - "AttributeDefinitions": [ + "Tags": [ { - "AttributeName": "id", - "AttributeType": "S" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "BillingMode": "PAY_PER_REQUEST" - } + ] + }, + "Type": "AWS::IAM::Role" }, - "ProcessingQueue": { - "Type": "AWS::SQS::Queue" + "StarterLambda": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "starter.zip" + }, + "Handler": "starter.handler", + "Role": { + "Fn::GetAtt": [ + "StarterLambdaRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ResolverLambdaRole": { - "Type": "AWS::IAM::Role", + "StarterLambdaRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -474,18 +472,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_schedule.json b/tests/translator/output/aws-cn/state_machine_with_schedule.json index 8730521be8..434e16586c 100644 --- a/tests/translator/output/aws-cn/state_machine_with_schedule.json +++ b/tests/translator/output/aws-cn/state_machine_with_schedule.json @@ -1,80 +1,80 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", "Properties": { - "State": "DISABLED", - "ScheduleExpression": "rate(1 minute)", - "Name": "TestSchedule", - "Description": "test schedule", + "Description": "test schedule", + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "State": "DISABLED", "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineScheduleEventRole", + "StateMachineScheduleEventRole", "Arn" ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Policies": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_schedule_dlq_retry_policy.json b/tests/translator/output/aws-cn/state_machine_with_schedule_dlq_retry_policy.json index 5d49175a96..95164ba8a7 100644 --- a/tests/translator/output/aws-cn/state_machine_with_schedule_dlq_retry_policy.json +++ b/tests/translator/output/aws-cn/state_machine_with_schedule_dlq_retry_policy.json @@ -1,87 +1,87 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", "Properties": { - "State": "DISABLED", - "ScheduleExpression": "rate(1 minute)", - "Name": "TestSchedule", - "Description": "test schedule", + "Description": "test schedule", + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "State": "DISABLED", "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "DeadLetterConfig": { - "Arn": "Arn" - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", "Arn": { "Ref": "StateMachine" - }, + }, + "DeadLetterConfig": { + "Arn": "Arn" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 300, + "MaximumEventAgeInSeconds": 300, "MaximumRetryAttempts": 5 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" + ] } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Policies": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_standard_logging.json b/tests/translator/output/aws-cn/state_machine_with_standard_logging.json index 315b60c2f2..3f36b9769c 100644 --- a/tests/translator/output/aws-cn/state_machine_with_standard_logging.json +++ b/tests/translator/output/aws-cn/state_machine_with_standard_logging.json @@ -1,180 +1,180 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "StandardLogGroup": { - "Type": "AWS::Logs::LogGroup" - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - }, - { - "PolicyName": "StateMachineRolePolicy1", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", - "logs:DescribeLogGroups" - ], - "Resource": [ - "*" - ], - "Effect": "Allow" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "StandardLogGroup": { + "Type": "AWS::Logs::LogGroup" + }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStandardStateMachineWithLogging", + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, "DefinitionSubstitutions": { "my_lambda_arn": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] } - }, + }, "LoggingConfiguration": { - "IncludeExecutionData": true, - "Level": "ALL", "Destinations": [ { "CloudWatchLogsLogGroup": { "LogGroupArn": { "Fn::GetAtt": [ - "StandardLogGroup", + "StandardLogGroup", "Arn" ] } } } + ], + "IncludeExecutionData": true, + "Level": "ALL" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + }, + "StateMachineName": "MyStandardStateMachineWithLogging", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy1" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_tags.json b/tests/translator/output/aws-cn/state_machine_with_tags.json index 6016da4201..615b6ced5b 100644 --- a/tests/translator/output/aws-cn/state_machine_with_tags.json +++ b/tests/translator/output/aws-cn/state_machine_with_tags.json @@ -1,105 +1,105 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithTags", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + }, + { + "Key": "TagTwo", + "Value": "ValueTwo" + }, + { + "Key": "TagOne", + "Value": "ValueOne" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Deny" + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - }, - { - "Value": "ValueTwo", - "Key": "TagTwo" - }, - { - "Value": "ValueOne", - "Key": "TagOne" + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithTags", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" - }, + "Key": "stateMachine:createdBy", + "Value": "SAM" + }, { - "Value": "ValueTwo", - "Key": "TagTwo" - }, + "Key": "TagTwo", + "Value": "ValueTwo" + }, { - "Value": "ValueOne", - "Key": "TagOne" + "Key": "TagOne", + "Value": "ValueOne" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_xray_policies.json b/tests/translator/output/aws-cn/state_machine_with_xray_policies.json index c073afdc68..f1bd868d1c 100644 --- a/tests/translator/output/aws-cn/state_machine_with_xray_policies.json +++ b/tests/translator/output/aws-cn/state_machine_with_xray_policies.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -77,13 +76,12 @@ "TracingConfiguration": { "Enabled": true } - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -96,20 +94,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/AWSXRayDaemonWriteAccess" ], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ "MyFunction", @@ -117,8 +114,10 @@ ] } } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } ], "Tags": [ @@ -127,7 +126,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/state_machine_with_xray_role.json b/tests/translator/output/aws-cn/state_machine_with_xray_role.json index 156d59d448..7efdf80eed 100644 --- a/tests/translator/output/aws-cn/state_machine_with_xray_role.json +++ b/tests/translator/output/aws-cn/state_machine_with_xray_role.json @@ -1,25 +1,25 @@ { - "Resources": { - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachineWithXRayTracing", - "TracingConfiguration": { - "Enabled": true - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithXRayTracing", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ], + "TracingConfiguration": { + "Enabled": true } + }, + "Type": "AWS::StepFunctions::StateMachine" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-cn/streams.json b/tests/translator/output/aws-cn/streams.json index ce73f1a36b..f6acb2d21f 100644 --- a/tests/translator/output/aws-cn/streams.json +++ b/tests/translator/output/aws-cn/streams.json @@ -1,7 +1,6 @@ { "Resources": { "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -15,56 +14,16 @@ ] }, "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "KinesisFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Handler": "stream.kinesis_handler", - "Role": { - "Fn::GetAtt": [ - "KinesisFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "MSKFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Handler": "stream.msk_handler", - "Role": { - "Fn::GetAtt": [ - "MSKFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 200, "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", @@ -72,39 +31,64 @@ "Ref": "DynamoDBFunction" }, "StartingPosition": "LATEST" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "KinesisFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" + }, + "Handler": "stream.kinesis_handler", + "Role": { + "Fn::GetAtt": [ + "KinesisFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "KinesisFunctionMyKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 100, "Enabled": false, @@ -113,76 +97,106 @@ "Ref": "KinesisFunction" }, "StartingPosition": "TRIM_HORIZON" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KinesisFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MSKFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" + }, + "Handler": "stream.msk_handler", + "Role": { + "Fn::GetAtt": [ + "MSKFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MSKFunctionMyMSKStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", "FunctionName": { "Ref": "MSKFunction" }, "StartingPosition": "LATEST", - "Topics": ["Topic1"] - } + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MSKFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/unsupported_resources.json b/tests/translator/output/aws-cn/unsupported_resources.json index b358015d05..5d0f51c19b 100644 --- a/tests/translator/output/aws-cn/unsupported_resources.json +++ b/tests/translator/output/aws-cn/unsupported_resources.json @@ -1,17 +1,17 @@ { "Resources": { - "UnknownTypeShouldBeAccepted": { - "Type": "AWS::Other::ABCD", + "ResourceMissingTypeShouldBeAccepted": { "Properties": { - "StageName": "Prod", - "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json" + "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json", + "StageName": "Prod" } }, - "ResourceMissingTypeShouldBeAccepted": { + "UnknownTypeShouldBeAccepted": { "Properties": { - "StageName": "Prod", - "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json" - } + "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json", + "StageName": "Prod" + }, + "Type": "AWS::Other::ABCD" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-cn/version_deletion_policy_precedence.json b/tests/translator/output/aws-cn/version_deletion_policy_precedence.json index 1d970410ad..bac509f484 100644 --- a/tests/translator/output/aws-cn/version_deletion_policy_precedence.json +++ b/tests/translator/output/aws-cn/version_deletion_policy_precedence.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,38 +20,53 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "MinimalFunction2": { + "DeletionPolicy": "Delete", "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunction2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "MinimalFunction2Aliaslive": { + "DeletionPolicy": "Delete", "Properties": { - "Name": "live", "FunctionName": { - "Ref": "MinimalFunction" + "Ref": "MinimalFunction2" }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "MinimalFunction2Version640128d35d", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction2Role": { + "DeletionPolicy": "Delete", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +79,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,64 +91,37 @@ "Value": "SAM" } ] - } - }, - "MinimalFunction2": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Delete", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunction2Role", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::IAM::Role" }, "MinimalFunction2Version640128d35d": { - "Type": "AWS::Lambda::Version", "DeletionPolicy": "Delete", "Properties": { "Description": "sam-testing", "FunctionName": { "Ref": "MinimalFunction2" } - } + }, + "Type": "AWS::Lambda::Version" }, - "MinimalFunction2Aliaslive": { - "Type": "AWS::Lambda::Alias", - "DeletionPolicy": "Delete", + "MinimalFunctionAliaslive": { "Properties": { - "Name": "live", "FunctionName": { - "Ref": "MinimalFunction2" + "Ref": "MinimalFunction" }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunction2Version640128d35d", + "MinimalFunctionVersion640128d35d", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "MinimalFunction2Role": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Delete", + "MinimalFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -146,7 +134,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -157,7 +146,18 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/alexa_skill.json b/tests/translator/output/aws-us-gov/alexa_skill.json index dad934a978..b205b82bec 100644 --- a/tests/translator/output/aws-us-gov/alexa_skill.json +++ b/tests/translator/output/aws-us-gov/alexa_skill.json @@ -1,72 +1,72 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", + "AlexaSkillFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/alexa_skill_with_skill_id.json b/tests/translator/output/aws-us-gov/alexa_skill_with_skill_id.json index 391e2fa72e..9b0f66834f 100644 --- a/tests/translator/output/aws-us-gov/alexa_skill_with_skill_id.json +++ b/tests/translator/output/aws-us-gov/alexa_skill_with_skill_id.json @@ -1,73 +1,73 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, - "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, + "Resources": { + "AlexaSkillFunc": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "EventSourceToken": "amzn1.ask.skill.12345678-1234-1234-1234-123456789", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com", - "EventSourceToken": "amzn1.ask.skill.12345678-1234-1234-1234-123456789" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Tags": [ + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } +} diff --git a/tests/translator/output/aws-us-gov/all_policy_templates.json b/tests/translator/output/aws-us-gov/all_policy_templates.json index 61d463baf1..006c4bf508 100644 --- a/tests/translator/output/aws-us-gov/all_policy_templates.json +++ b/tests/translator/output/aws-us-gov/all_policy_templates.json @@ -1,1500 +1,1498 @@ { "Resources": { "KitchenSinkFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "KitchenSinkFunctionRole", + "KitchenSinkFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "KitchenSinkFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "KitchenSinkFunctionRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "sqs:ChangeMessageVisibility", - "sqs:ChangeMessageVisibilityBatch", - "sqs:DeleteMessage", - "sqs:DeleteMessageBatch", - "sqs:GetQueueAttributes", + "sqs:ChangeMessageVisibility", + "sqs:ChangeMessageVisibilityBatch", + "sqs:DeleteMessage", + "sqs:DeleteMessageBatch", + "sqs:GetQueueAttributes", "sqs:ReceiveMessage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy0" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { "functionName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy1" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ "cloudwatch:DescribeAlarmHistory" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy2" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy3", "PolicyDocument": { "Statement": [ { "Action": [ "cloudwatch:PutMetricData" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy3" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy4", "PolicyDocument": { "Statement": [ { "Action": [ - "ec2:DescribeRegions", + "ec2:DescribeRegions", "ec2:DescribeInstances" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy4" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy5", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:GetItem", - "dynamodb:DeleteItem", - "dynamodb:PutItem", - "dynamodb:Scan", - "dynamodb:Query", - "dynamodb:UpdateItem", - "dynamodb:BatchWriteItem", - "dynamodb:BatchGetItem", - "dynamodb:DescribeTable", + "dynamodb:GetItem", + "dynamodb:DeleteItem", + "dynamodb:PutItem", + "dynamodb:Scan", + "dynamodb:Query", + "dynamodb:UpdateItem", + "dynamodb:BatchWriteItem", + "dynamodb:BatchGetItem", + "dynamodb:DescribeTable", "dynamodb:ConditionCheckItem" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", { "tableName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy5" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy6", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:GetItem", - "dynamodb:Scan", - "dynamodb:Query", - "dynamodb:BatchGetItem", + "dynamodb:GetItem", + "dynamodb:Scan", + "dynamodb:Query", + "dynamodb:BatchGetItem", "dynamodb:DescribeTable" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/index/*", { "tableName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy6" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy7", "PolicyDocument": { "Statement": [ { "Action": [ "ses:SendBounce" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy7" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy8", "PolicyDocument": { "Statement": [ { "Action": [ - "es:ESHttpPost", + "es:ESHttpPost", "es:ESHttpPut" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain/${domainName}/*", + "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain/${domainName}/*", { "domainName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy8" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy9", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetObjectVersion", + "s3:GetObject", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetObjectVersion", "s3:GetLifecycleConfiguration" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy9" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy10", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:GetLifecycleConfiguration", - "s3:PutLifecycleConfiguration", + "s3:GetObject", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:GetLifecycleConfiguration", + "s3:PutLifecycleConfiguration", "s3:DeleteObject" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] - }, + }, { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy10" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy11", "PolicyDocument": { "Statement": [ { "Action": [ "ec2:DescribeImages" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy11" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy12", "PolicyDocument": { "Statement": [ { "Action": [ "cloudformation:DescribeStacks" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/*" - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy12" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy13", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CompareFaces", - "rekognition:DetectFaces", - "rekognition:DetectLabels", + "rekognition:CompareFaces", + "rekognition:DetectFaces", + "rekognition:DetectLabels", "rekognition:DetectModerationLabels" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy13" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy14", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:ListCollections", - "rekognition:ListFaces", - "rekognition:SearchFaces", + "rekognition:ListCollections", + "rekognition:ListFaces", + "rekognition:SearchFaces", "rekognition:SearchFacesByImage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy14" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy15", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CreateCollection", + "rekognition:CreateCollection", "rekognition:IndexFaces" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy15" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy16", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy16" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy17", "PolicyDocument": { "Statement": [ { "Action": [ "sns:Publish" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}", + "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}", { "topicName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy17" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy18", "PolicyDocument": { "Statement": [ { "Action": [ - "ec2:CreateNetworkInterface", - "ec2:DeleteNetworkInterface", - "ec2:DescribeNetworkInterfaces", + "ec2:CreateNetworkInterface", + "ec2:DeleteNetworkInterface", + "ec2:DescribeNetworkInterfaces", "ec2:DetachNetworkInterface" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy18" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy19", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:DescribeStream", - "dynamodb:GetRecords", + "dynamodb:DescribeStream", + "dynamodb:GetRecords", "dynamodb:GetShardIterator" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/${streamName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/${streamName}", { - "streamName": "name", + "streamName": "name", "tableName": "name" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ "dynamodb:ListStreams" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/stream/*", { "tableName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy19" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy20", "PolicyDocument": { "Statement": [ { "Action": [ - "kinesis:ListStreams", + "kinesis:ListStreams", "kinesis:DescribeLimits" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/*" - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "kinesis:DescribeStream", - "kinesis:DescribeStreamSummary", - "kinesis:GetRecords", + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetRecords", "kinesis:GetShardIterator" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", + "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", { "streamName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy20" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy21", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:GetIdentityVerificationAttributes", - "ses:SendEmail", - "ses:SendRawEmail", + "ses:GetIdentityVerificationAttributes", + "ses:SendEmail", + "ses:SendRawEmail", "ses:VerifyEmailIdentity" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy21" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy22", "PolicyDocument": { "Statement": [ { "Action": [ - "sns:ListSubscriptionsByTopic", - "sns:CreateTopic", - "sns:SetTopicAttributes", - "sns:Subscribe", + "sns:ListSubscriptionsByTopic", + "sns:CreateTopic", + "sns:SetTopicAttributes", + "sns:Subscribe", "sns:Publish" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}*", + "arn:${AWS::Partition}:sns:${AWS::Region}:${AWS::AccountId}:${topicName}*", { "topicName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy22" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy23", "PolicyDocument": { "Statement": [ { "Action": [ - "kinesis:AddTagsToStream", - "kinesis:CreateStream", - "kinesis:DecreaseStreamRetentionPeriod", - "kinesis:DeleteStream", - "kinesis:DescribeStream", - "kinesis:DescribeStreamSummary", - "kinesis:GetShardIterator", - "kinesis:IncreaseStreamRetentionPeriod", - "kinesis:ListTagsForStream", - "kinesis:MergeShards", - "kinesis:PutRecord", - "kinesis:PutRecords", - "kinesis:SplitShard", + "kinesis:AddTagsToStream", + "kinesis:CreateStream", + "kinesis:DecreaseStreamRetentionPeriod", + "kinesis:DeleteStream", + "kinesis:DescribeStream", + "kinesis:DescribeStreamSummary", + "kinesis:GetShardIterator", + "kinesis:IncreaseStreamRetentionPeriod", + "kinesis:ListTagsForStream", + "kinesis:MergeShards", + "kinesis:PutRecord", + "kinesis:PutRecords", + "kinesis:SplitShard", "kinesis:RemoveTagsFromStream" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", + "arn:${AWS::Partition}:kinesis:${AWS::Region}:${AWS::AccountId}:stream/${streamName}", { "streamName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy23" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy24", "PolicyDocument": { "Statement": [ { - "Action": "kms:Decrypt", + "Action": "kms:Decrypt", + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", + "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", { "keyId": "keyId" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy24" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy25", "PolicyDocument": { "Statement": [ { "Action": [ - "polly:GetLexicon", + "polly:GetLexicon", "polly:DeleteLexicon" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/${lexiconName}", + "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/${lexiconName}", { "lexiconName": "name" } ] } - ], - "Effect": "Allow" - }, + ] + }, { "Action": [ - "polly:DescribeVoices", - "polly:ListLexicons", - "polly:PutLexicon", + "polly:DescribeVoices", + "polly:ListLexicons", + "polly:PutLexicon", "polly:SynthesizeSpeech" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:polly:${AWS::Region}:${AWS::AccountId}:lexicon/*" } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy25" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy26", "PolicyDocument": { "Statement": [ { "Action": [ - "s3:GetObject", - "s3:GetObjectAcl", - "s3:GetObjectVersion", - "s3:PutObject", - "s3:PutObjectAcl", - "s3:DeleteObject", - "s3:DeleteObjectTagging", - "s3:DeleteObjectVersionTagging", - "s3:GetObjectTagging", - "s3:GetObjectVersionTagging", - "s3:PutObjectTagging", + "s3:GetObject", + "s3:GetObjectAcl", + "s3:GetObjectVersion", + "s3:PutObject", + "s3:PutObjectAcl", + "s3:DeleteObject", + "s3:DeleteObjectTagging", + "s3:DeleteObjectVersionTagging", + "s3:GetObjectTagging", + "s3:GetObjectVersionTagging", + "s3:PutObjectTagging", "s3:PutObjectVersionTagging" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}/*", + "arn:${AWS::Partition}:s3:::${bucketName}/*", { "bucketName": "name" } ] } - ], - "Effect": "Allow" - }, + ] + }, { "Action": [ - "s3:ListBucket", - "s3:GetBucketLocation", - "s3:GetLifecycleConfiguration", + "s3:ListBucket", + "s3:GetBucketLocation", + "s3:GetLifecycleConfiguration", "s3:PutLifecycleConfiguration" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ - "arn:${AWS::Partition}:s3:::${bucketName}", + "arn:${AWS::Partition}:s3:::${bucketName}", { "bucketName": "name" } ] } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy26" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy27", "PolicyDocument": { "Statement": [ { "Action": [ - "codepipeline:PutJobSuccessResult", + "codepipeline:PutJobSuccessResult", "codepipeline:PutJobFailureResult" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy27" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy28", "PolicyDocument": { "Statement": [ { "Action": [ - "serverlessrepo:CreateApplication", - "serverlessrepo:CreateApplicationVersion", - "serverlessrepo:UpdateApplication", - "serverlessrepo:GetApplication", - "serverlessrepo:ListApplications", - "serverlessrepo:ListApplicationVersions", + "serverlessrepo:CreateApplication", + "serverlessrepo:CreateApplicationVersion", + "serverlessrepo:UpdateApplication", + "serverlessrepo:GetApplication", + "serverlessrepo:ListApplications", + "serverlessrepo:ListApplicationVersions", "serverlessrepo:ListApplicationDependencies" - ], + ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:serverlessrepo:${AWS::Region}:${AWS::AccountId}:applications/*" } - ], - "Effect": "Allow" + ] } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy28" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy29", "PolicyDocument": { "Statement": [ { "Action": [ "ec2:CopyImage" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:image/${imageId}", + "arn:${AWS::Partition}:ec2:${AWS::Region}:${AWS::AccountId}:image/${imageId}", { "imageId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy29" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy30", "PolicyDocument": { "Statement": [ { "Action": [ "codepipeline:ListPipelineExecutions" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipelinename}", + "arn:${AWS::Partition}:codepipeline:${AWS::Region}:${AWS::AccountId}:${pipelinename}", { "pipelinename": "pipeline" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy30" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy31", "PolicyDocument": { "Statement": [ { "Action": [ - "cloudwatch:GetDashboard", - "cloudwatch:ListDashboards", - "cloudwatch:PutDashboard", + "cloudwatch:GetDashboard", + "cloudwatch:ListDashboards", + "cloudwatch:PutDashboard", "cloudwatch:ListMetrics" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy31" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy32", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:CompareFaces", + "rekognition:CompareFaces", "rekognition:DetectFaces" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy32" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy33", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:DetectLabels", + "rekognition:DetectLabels", "rekognition:DetectModerationLabels" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy33" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy34", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:CreateBackup", + "dynamodb:CreateBackup", "dynamodb:DescribeContinuousBackups" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "table" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "dynamodb:DeleteBackup", - "dynamodb:DescribeBackup", + "dynamodb:DeleteBackup", + "dynamodb:DescribeBackup", "dynamodb:ListBackups" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", { "tableName": "table" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy34" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy35", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:RestoreTableFromBackup" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}/backup/*", { "tableName": "table" } ] - }, - "Effect": "Allow" - }, + } + }, { "Action": [ - "dynamodb:PutItem", - "dynamodb:UpdateItem", - "dynamodb:DeleteItem", - "dynamodb:GetItem", - "dynamodb:Query", - "dynamodb:Scan", + "dynamodb:PutItem", + "dynamodb:UpdateItem", + "dynamodb:DeleteItem", + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", "dynamodb:BatchWriteItem" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "table" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy35" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy36", "PolicyDocument": { "Statement": [ { "Action": [ - "comprehend:BatchDetectKeyPhrases", - "comprehend:DetectDominantLanguage", - "comprehend:DetectEntities", - "comprehend:BatchDetectEntities", - "comprehend:DetectKeyPhrases", - "comprehend:DetectSentiment", - "comprehend:BatchDetectDominantLanguage", + "comprehend:BatchDetectKeyPhrases", + "comprehend:DetectDominantLanguage", + "comprehend:DetectEntities", + "comprehend:BatchDetectEntities", + "comprehend:DetectKeyPhrases", + "comprehend:DetectSentiment", + "comprehend:BatchDetectDominantLanguage", "comprehend:BatchDetectSentiment" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy36" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy37", "PolicyDocument": { "Statement": [ { "Action": [ - "secretsmanager:DescribeSecret", - "secretsmanager:GetSecretValue", - "secretsmanager:PutSecretValue", + "secretsmanager:DescribeSecret", + "secretsmanager:GetSecretValue", + "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" - ], - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" - }, - "Effect": "Allow", + ], "Condition": { "StringEquals": { "secretsmanager:resource/AllowRotationLambdaArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}", { "functionName": "function" } ] } } + }, + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" } - }, + }, { "Action": [ "secretsmanager:GetRandomPassword" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy37" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy38", "PolicyDocument": { "Statement": [ { "Action": [ "mobileanalytics:PutEvents" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy38" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy39", "PolicyDocument": { "Statement": [ { "Action": [ - "mobiletargeting:GetEndpoint", - "mobiletargeting:UpdateEndpoint", + "mobiletargeting:GetEndpoint", + "mobiletargeting:UpdateEndpoint", "mobiletargeting:UpdateEndpointsBatch" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${pinpointApplicationId}/endpoints/*", + "arn:${AWS::Partition}:mobiletargeting:${AWS::Region}:${AWS::AccountId}:apps/${pinpointApplicationId}/endpoints/*", { "pinpointApplicationId": "id" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy39" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy40", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:DetectFaces", - "rekognition:DetectLabels", - "rekognition:DetectModerationLabels", + "rekognition:DetectFaces", + "rekognition:DetectLabels", + "rekognition:DetectModerationLabels", "rekognition:DetectText" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy40" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy41", "PolicyDocument": { "Statement": [ { "Action": [ - "rekognition:IndexFaces", - "rekognition:DeleteFaces", - "rekognition:SearchFaces", - "rekognition:SearchFacesByImage", + "rekognition:IndexFaces", + "rekognition:DeleteFaces", + "rekognition:SearchFaces", + "rekognition:SearchFacesByImage", "rekognition:ListFaces" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", + "arn:${AWS::Partition}:rekognition:${AWS::Region}:${AWS::AccountId}:collection/${collectionId}", { "collectionId": "collection" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy41" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy42", "PolicyDocument": { "Statement": [ { "Action": [ - "eks:DescribeCluster", + "eks:DescribeCluster", "eks:ListClusters" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy42" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy43", "PolicyDocument": { "Statement": [ { "Action": [ - "ce:GetCostAndUsage", - "ce:GetDimensionValues", - "ce:GetReservationCoverage", - "ce:GetReservationPurchaseRecommendation", - "ce:GetReservationUtilization", + "ce:GetCostAndUsage", + "ce:GetDimensionValues", + "ce:GetReservationCoverage", + "ce:GetReservationPurchaseRecommendation", + "ce:GetReservationUtilization", "ce:GetTags" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy43" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy44", "PolicyDocument": { "Statement": [ { "Action": [ "organizations:ListAccounts" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy44" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy45", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:UpdateTable" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", + "arn:${AWS::Partition}:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${tableName}", { "tableName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy45" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy46", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:GetIdentityVerificationAttributes", - "ses:SendEmail", - "ses:SendRawEmail", - "ses:SendTemplatedEmail", - "ses:SendBulkTemplatedEmail", + "ses:GetIdentityVerificationAttributes", + "ses:SendEmail", + "ses:SendRawEmail", + "ses:SendTemplatedEmail", + "ses:SendBulkTemplatedEmail", "ses:VerifyEmailIdentity" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", + "arn:${AWS::Partition}:ses:${AWS::Region}:${AWS::AccountId}:identity/${identityName}", { "identityName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy46" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy47", "PolicyDocument": { "Statement": [ { "Action": [ - "ses:CreateTemplate", - "ses:GetTemplate", - "ses:ListTemplates", - "ses:UpdateTemplate", - "ses:DeleteTemplate", + "ses:CreateTemplate", + "ses:GetTemplate", + "ses:ListTemplates", + "ses:UpdateTemplate", + "ses:DeleteTemplate", "ses:TestRenderTemplate" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy47" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy48", "PolicyDocument": { "Statement": [ { "Action": [ "logs:FilterLogEvents" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${logGroupName}:log-stream:*", + "arn:${AWS::Partition}:logs:${AWS::Region}:${AWS::AccountId}:log-group:${logGroupName}:log-stream:*", { "logGroupName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy48" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy49", "PolicyDocument": { "Statement": [ { "Action": [ "ssm:DescribeParameters" - ], - "Resource": "*", - "Effect": "Allow" - }, + ], + "Effect": "Allow", + "Resource": "*" + }, { "Action": [ - "ssm:GetParameters", - "ssm:GetParameter", + "ssm:GetParameters", + "ssm:GetParameter", "ssm:GetParametersByPath" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${parameterName}", + "arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${parameterName}", { "parameterName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy49" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy50", "PolicyDocument": { "Statement": [ { "Action": [ "states:StartExecution" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", { "stateMachineName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy50" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy51", "PolicyDocument": { "Statement": [ { "Action": [ - "codecommit:GitPull", - "codecommit:GitPush", - "codecommit:CreateBranch", - "codecommit:DeleteBranch", - "codecommit:GetBranch", - "codecommit:ListBranches", - "codecommit:MergeBranchesByFastForward", - "codecommit:MergeBranchesBySquash", - "codecommit:MergeBranchesByThreeWay", - "codecommit:UpdateDefaultBranch", - "codecommit:BatchDescribeMergeConflicts", - "codecommit:CreateUnreferencedMergeCommit", - "codecommit:DescribeMergeConflicts", - "codecommit:GetMergeCommit", - "codecommit:GetMergeOptions", - "codecommit:BatchGetPullRequests", - "codecommit:CreatePullRequest", - "codecommit:DescribePullRequestEvents", - "codecommit:GetCommentsForPullRequest", - "codecommit:GetCommitsFromMergeBase", - "codecommit:GetMergeConflicts", - "codecommit:GetPullRequest", - "codecommit:ListPullRequests", - "codecommit:MergePullRequestByFastForward", - "codecommit:MergePullRequestBySquash", - "codecommit:MergePullRequestByThreeWay", - "codecommit:PostCommentForPullRequest", - "codecommit:UpdatePullRequestDescription", - "codecommit:UpdatePullRequestStatus", - "codecommit:UpdatePullRequestTitle", - "codecommit:DeleteFile", - "codecommit:GetBlob", - "codecommit:GetFile", - "codecommit:GetFolder", - "codecommit:PutFile", - "codecommit:DeleteCommentContent", - "codecommit:GetComment", - "codecommit:GetCommentsForComparedCommit", - "codecommit:PostCommentForComparedCommit", - "codecommit:PostCommentReply", - "codecommit:UpdateComment", - "codecommit:BatchGetCommits", - "codecommit:CreateCommit", - "codecommit:GetCommit", - "codecommit:GetCommitHistory", - "codecommit:GetDifferences", - "codecommit:GetObjectIdentifier", - "codecommit:GetReferences", - "codecommit:GetTree", - "codecommit:GetRepository", - "codecommit:UpdateRepositoryDescription", - "codecommit:ListTagsForResource", - "codecommit:TagResource", - "codecommit:UntagResource", - "codecommit:GetRepositoryTriggers", - "codecommit:PutRepositoryTriggers", - "codecommit:TestRepositoryTriggers", - "codecommit:GetBranch", - "codecommit:GetCommit", - "codecommit:UploadArchive", - "codecommit:GetUploadArchiveStatus", + "codecommit:GitPull", + "codecommit:GitPush", + "codecommit:CreateBranch", + "codecommit:DeleteBranch", + "codecommit:GetBranch", + "codecommit:ListBranches", + "codecommit:MergeBranchesByFastForward", + "codecommit:MergeBranchesBySquash", + "codecommit:MergeBranchesByThreeWay", + "codecommit:UpdateDefaultBranch", + "codecommit:BatchDescribeMergeConflicts", + "codecommit:CreateUnreferencedMergeCommit", + "codecommit:DescribeMergeConflicts", + "codecommit:GetMergeCommit", + "codecommit:GetMergeOptions", + "codecommit:BatchGetPullRequests", + "codecommit:CreatePullRequest", + "codecommit:DescribePullRequestEvents", + "codecommit:GetCommentsForPullRequest", + "codecommit:GetCommitsFromMergeBase", + "codecommit:GetMergeConflicts", + "codecommit:GetPullRequest", + "codecommit:ListPullRequests", + "codecommit:MergePullRequestByFastForward", + "codecommit:MergePullRequestBySquash", + "codecommit:MergePullRequestByThreeWay", + "codecommit:PostCommentForPullRequest", + "codecommit:UpdatePullRequestDescription", + "codecommit:UpdatePullRequestStatus", + "codecommit:UpdatePullRequestTitle", + "codecommit:DeleteFile", + "codecommit:GetBlob", + "codecommit:GetFile", + "codecommit:GetFolder", + "codecommit:PutFile", + "codecommit:DeleteCommentContent", + "codecommit:GetComment", + "codecommit:GetCommentsForComparedCommit", + "codecommit:PostCommentForComparedCommit", + "codecommit:PostCommentReply", + "codecommit:UpdateComment", + "codecommit:BatchGetCommits", + "codecommit:CreateCommit", + "codecommit:GetCommit", + "codecommit:GetCommitHistory", + "codecommit:GetDifferences", + "codecommit:GetObjectIdentifier", + "codecommit:GetReferences", + "codecommit:GetTree", + "codecommit:GetRepository", + "codecommit:UpdateRepositoryDescription", + "codecommit:ListTagsForResource", + "codecommit:TagResource", + "codecommit:UntagResource", + "codecommit:GetRepositoryTriggers", + "codecommit:PutRepositoryTriggers", + "codecommit:TestRepositoryTriggers", + "codecommit:GetBranch", + "codecommit:GetCommit", + "codecommit:UploadArchive", + "codecommit:GetUploadArchiveStatus", "codecommit:CancelUploadArchive" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", + "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", { "repositoryName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy51" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy52", "PolicyDocument": { "Statement": [ { "Action": [ - "codecommit:GitPull", - "codecommit:GetBranch", - "codecommit:ListBranches", - "codecommit:BatchDescribeMergeConflicts", - "codecommit:DescribeMergeConflicts", - "codecommit:GetMergeCommit", - "codecommit:GetMergeOptions", - "codecommit:BatchGetPullRequests", - "codecommit:DescribePullRequestEvents", - "codecommit:GetCommentsForPullRequest", - "codecommit:GetCommitsFromMergeBase", - "codecommit:GetMergeConflicts", - "codecommit:GetPullRequest", - "codecommit:ListPullRequests", - "codecommit:GetBlob", - "codecommit:GetFile", - "codecommit:GetFolder", - "codecommit:GetComment", - "codecommit:GetCommentsForComparedCommit", - "codecommit:BatchGetCommits", - "codecommit:GetCommit", - "codecommit:GetCommitHistory", - "codecommit:GetDifferences", - "codecommit:GetObjectIdentifier", - "codecommit:GetReferences", - "codecommit:GetTree", - "codecommit:GetRepository", - "codecommit:ListTagsForResource", - "codecommit:GetRepositoryTriggers", - "codecommit:TestRepositoryTriggers", - "codecommit:GetBranch", - "codecommit:GetCommit", + "codecommit:GitPull", + "codecommit:GetBranch", + "codecommit:ListBranches", + "codecommit:BatchDescribeMergeConflicts", + "codecommit:DescribeMergeConflicts", + "codecommit:GetMergeCommit", + "codecommit:GetMergeOptions", + "codecommit:BatchGetPullRequests", + "codecommit:DescribePullRequestEvents", + "codecommit:GetCommentsForPullRequest", + "codecommit:GetCommitsFromMergeBase", + "codecommit:GetMergeConflicts", + "codecommit:GetPullRequest", + "codecommit:ListPullRequests", + "codecommit:GetBlob", + "codecommit:GetFile", + "codecommit:GetFolder", + "codecommit:GetComment", + "codecommit:GetCommentsForComparedCommit", + "codecommit:BatchGetCommits", + "codecommit:GetCommit", + "codecommit:GetCommitHistory", + "codecommit:GetDifferences", + "codecommit:GetObjectIdentifier", + "codecommit:GetReferences", + "codecommit:GetTree", + "codecommit:GetRepository", + "codecommit:ListTagsForResource", + "codecommit:GetRepositoryTriggers", + "codecommit:TestRepositoryTriggers", + "codecommit:GetBranch", + "codecommit:GetCommit", "codecommit:GetUploadArchiveStatus" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", + "arn:${AWS::Partition}:codecommit:${AWS::Region}:${AWS::AccountId}:${repositoryName}", { "repositoryName": "name" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy52" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy53", "PolicyDocument": { "Statement": [ { - "Action": "kms:Encrypt", + "Action": "kms:Encrypt", + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", + "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/${keyId}", { "keyId": "keyId" } ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "KitchenSinkFunctionRolePolicy53" + }, { - "PolicyName": "KitchenSinkFunctionRolePolicy54", "PolicyDocument": { "Statement": [ { "Action": [ - "athena:ListWorkGroups", - "athena:GetExecutionEngine", - "athena:GetExecutionEngines", - "athena:GetNamespace", - "athena:GetCatalogs", - "athena:GetNamespaces", - "athena:GetTables", + "athena:ListWorkGroups", + "athena:GetExecutionEngine", + "athena:GetExecutionEngines", + "athena:GetNamespace", + "athena:GetCatalogs", + "athena:GetNamespaces", + "athena:GetTables", "athena:GetTable" - ], - "Resource": "*", - "Effect": "Allow" - }, - { - "Action": [ - "athena:StartQueryExecution", - "athena:GetQueryResults", - "athena:DeleteNamedQuery", - "athena:GetNamedQuery", - "athena:ListQueryExecutions", - "athena:StopQueryExecution", - "athena:GetQueryResultsStream", - "athena:ListNamedQueries", - "athena:CreateNamedQuery", - "athena:GetQueryExecution", - "athena:BatchGetNamedQuery", - "athena:BatchGetQueryExecution", + ], + "Effect": "Allow", + "Resource": "*" + }, + { + "Action": [ + "athena:StartQueryExecution", + "athena:GetQueryResults", + "athena:DeleteNamedQuery", + "athena:GetNamedQuery", + "athena:ListQueryExecutions", + "athena:StopQueryExecution", + "athena:GetQueryResultsStream", + "athena:ListNamedQueries", + "athena:CreateNamedQuery", + "athena:GetQueryExecution", + "athena:BatchGetNamedQuery", + "athena:BatchGetQueryExecution", "athena:GetWorkGroup" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/${workgroupName}", + "arn:${AWS::Partition}:athena:${AWS::Region}:${AWS::AccountId}:workgroup/${workgroupName}", { "workgroupName": "name" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy54" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy55", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "s3:PutObject", "s3:PutObjectAcl", "s3:PutLifecycleConfiguration" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -1515,19 +1513,19 @@ ] } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy55" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy56", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "dynamodb:PutItem", "dynamodb:UpdateItem", "dynamodb:BatchWriteItem" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -1548,14 +1546,15 @@ ] } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy56" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy57", "PolicyDocument": { "Statement": [ { "Action": "events:PutEvents", + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:event-bus/${eventBusName}", @@ -1563,20 +1562,20 @@ "eventBusName": "name" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy57" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy58", "PolicyDocument": { "Statement": [ { "Action": [ "acm:GetCertificate" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${certificateArn}", @@ -1584,20 +1583,20 @@ "certificateArn": "arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy58" }, { - "PolicyName": "KitchenSinkFunctionRolePolicy59", "PolicyDocument": { "Statement": [ { "Action": [ "route53:ChangeResourceRecordSets" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:route53:::hostedzone/${HostedZoneId}", @@ -1605,20 +1604,21 @@ "HostedZoneId": "test" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "KitchenSinkFunctionRolePolicy59" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_cache.json b/tests/translator/output/aws-us-gov/api_cache.json index 35bdeb0800..35af71ab78 100644 --- a/tests/translator/output/aws-us-gov/api_cache.json +++ b/tests/translator/output/aws-us-gov/api_cache.json @@ -1,117 +1,117 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { - "CacheClusterEnabled": true, + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", "DeploymentId": { "Ref": "HtmlApiDeploymentf117c932f7" - }, + }, "RestApiId": { "Ref": "HtmlApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6" - } - }, + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_description.json b/tests/translator/output/aws-us-gov/api_description.json index aef917ae18..08f043bcab 100644 --- a/tests/translator/output/aws-us-gov/api_description.json +++ b/tests/translator/output/aws-us-gov/api_description.json @@ -1,81 +1,9 @@ { "Resources": { - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "Api" - }, - "StageName": "Prod" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "Api" - } - ] - } - } - }, - "ApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, "Api": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "BodyS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "webpage_swagger.json" }, "Description": "my description", @@ -87,30 +15,102 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "Api", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_endpoint_configuration.json b/tests/translator/output/aws-us-gov/api_endpoint_configuration.json index 1b805f0038..9fdd621ef2 100644 --- a/tests/translator/output/aws-us-gov/api_endpoint_configuration.json +++ b/tests/translator/output/aws-us-gov/api_endpoint_configuration.json @@ -5,14 +5,52 @@ } }, "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -22,17 +60,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -45,122 +103,41 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment5b2cb4ba8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -178,7 +155,30 @@ "Ref": "EndpointConfig" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5b2cb4ba8f": { + "Properties": { + "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_endpoint_configuration_with_vpcendpoint.json b/tests/translator/output/aws-us-gov/api_endpoint_configuration_with_vpcendpoint.json index e67d0c9df0..1aeccfc925 100644 --- a/tests/translator/output/aws-us-gov/api_endpoint_configuration_with_vpcendpoint.json +++ b/tests/translator/output/aws-us-gov/api_endpoint_configuration_with_vpcendpoint.json @@ -1,21 +1,64 @@ { "Parameters": { - "VpcEndpointId": { + "EndpointConfigType": { "Type": "String" }, - "EndpointConfigType": { + "VpcEndpointId": { "Type": "String" } }, "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ], + "VpcEndpointIds": [ + { + "Ref": "VpcEndpointId" + } + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ImplicitApiFunctionRole", @@ -25,17 +68,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -48,141 +111,55 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment5b2cb4ba8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "VpcEndpointIds": [ - { - "Ref": "VpcEndpointId" - } - ], - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, "swagger": "2.0" }, "EndpointConfiguration": { - "VpcEndpointIds": [ + "Types": [ { - "Ref": "VpcEndpointId" + "Ref": "EndpointConfigType" } ], - "Types": [ + "VpcEndpointIds": [ { - "Ref": "EndpointConfigType" + "Ref": "VpcEndpointId" } ] }, @@ -191,7 +168,30 @@ "Ref": "EndpointConfigType" } } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5b2cb4ba8f": { + "Properties": { + "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition.json b/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition.json index ae99acb982..ef603bc1c6 100644 --- a/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition.json +++ b/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition.json @@ -1,178 +1,178 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] }, - "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Description": "sam-app\nSample SAM Template for sam-app\n", + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } + } + }, + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + }, + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - } + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_else_case.json b/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_else_case.json index 916ae15b55..8615de66c5 100644 --- a/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_else_case.json +++ b/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_else_case.json @@ -1,166 +1,166 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] }, - "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Description": "sam-app\nSample SAM Template for sam-app\n", + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" ] - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_then_case.json b/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_then_case.json index 4ee79d820e..830677d308 100644 --- a/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_then_case.json +++ b/tests/translator/output/aws-us-gov/api_http_paths_with_if_condition_no_value_then_case.json @@ -1,66 +1,115 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", + "MyApi": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 1.0, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": [ + "$request.header.Authorization" + ], + "type": "request" + } } } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "Ref": "AWS::NoValue" + }, + { + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + } + }, + "Type": "AWS::ApiGatewayV2::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -80,87 +129,38 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + "MyAuthFnRole": { "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "Ref": "AWS::NoValue" - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - } - ] - } - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "MyLambdaAuthUpdated": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "authorizerResultTtlInSeconds": 37, - "identitySource": [ - "$request.header.Authorization" - ], - "authorizerPayloadFormatVersion": 1.0 - } - } - } - }, - "tags": [ + "AssumeRolePolicyDocument": { + "Statement": [ { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_request_model.json b/tests/translator/output/aws-us-gov/api_request_model.json index 9cd385cd94..4818ccad07 100644 --- a/tests/translator/output/aws-us-gov/api_request_model.json +++ b/tests/translator/output/aws-us-gov/api_request_model.json @@ -1,195 +1,195 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymenta918aefe10" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlFunctionAnyPathPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", - { - "__ApiId__": "HtmlApi", - "__Stage__": "*" - } - ] - } - } - }, - "HtmlApiDeploymenta918aefe10": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: a918aefe10cedb759cd5d8b070774d1e1804de32", - "StageName": "Stage" - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, "in": "body", "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "responses": {}, + } + } + }, + "/any": { + "x-amazon-apigateway-any-method": { "parameters": [ { "in": "body", "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" - }, - "required": true + } + } + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" } } } - } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymenta918aefe10": { + "Properties": { + "Description": "RestApi deployment id: a918aefe10cedb759cd5d8b070774d1e1804de32", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymenta918aefe10" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionAnyPathPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_request_model_openapi_3.json b/tests/translator/output/aws-us-gov/api_request_model_openapi_3.json index a8bb14db30..207893e540 100644 --- a/tests/translator/output/aws-us-gov/api_request_model_openapi_3.json +++ b/tests/translator/output/aws-us-gov/api_request_model_openapi_3.json @@ -1,101 +1,37 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "components": { + "schemas": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" } - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment2274fb58ae" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionIamPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "HtmlApi" + }, + "securitySchemes": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" } } - ] - } - } - }, - "HtmlFunctionAnyIamPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", - { - "__ApiId__": { - "Ref": "HtmlApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0", "paths": { - "/iam": { + "/": { "get": { "requestBody": { "content": { @@ -107,24 +43,18 @@ }, "required": true }, + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } }, - "/": { - "get": { + "/any/iam": { + "x-amazon-apigateway-any-method": { "requestBody": { "content": { "application/json": { @@ -135,32 +65,24 @@ }, "required": true }, + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/iam": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ], + "/iam": { + "get": { "requestBody": { "content": { "application/json": { @@ -170,26 +92,19 @@ } }, "required": true - } - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - }, - "schemas": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + }, + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } } } @@ -204,58 +119,143 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "HtmlApiDeployment2274fb58ae": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 2274fb58ae60fc2a69a3feb3b433d9bcf6947be5", + "RestApiId": { + "Ref": "HtmlApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment2274fb58ae" + }, "RestApiId": { "Ref": "HtmlApi" }, - "Description": "RestApi deployment id: 2274fb58ae60fc2a69a3feb3b433d9bcf6947be5" - } + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionAnyIamPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HtmlFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionIamPermissionProd": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_request_model_with_validator.json b/tests/translator/output/aws-us-gov/api_request_model_with_validator.json index e7a1e3218f..21e99ae378 100644 --- a/tests/translator/output/aws-us-gov/api_request_model_with_validator.json +++ b/tests/translator/output/aws-us-gov/api_request_model_with_validator.json @@ -1,837 +1,837 @@ { "Resources": { - "HtmlFunctionOnlyBodyDefinitionFalse": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionOnlyBodyDefinitionFalseRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidationRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionOnlyRequestDefinitionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalseRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidation": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionNotDefinedValidationRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionNotDefinedValidation" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlFunctionMixinValidationRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentf186539e09" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/only-request-true": { + "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" - } - }, - "x-amazon-apigateway-request-validator": "params-only", - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-and-params", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-and-params" + } + }, + "/mixin": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/mixin": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionMixinValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-only", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-only" + } + }, + "/no-validation": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-request-false": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/not-defined": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-body-true": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-only", - "responses": {}, + } + } + }, + "/only-body-false": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/not-defined": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" } - }, - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/only-body-true": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/no-validation": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "body-only" + } + }, + "/only-request-false": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - }, - "/only-body-false": { - "get": { + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "no-validation", - "responses": {}, + }, + "x-amazon-apigateway-request-validator": "no-validation" + } + }, + "/only-request-true": { + "get": { "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "params-only" } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-request-validators": { - "params-only": { - "validateRequestParameters": true, - "validateRequestBody": false - }, "body-and-params": { - "validateRequestParameters": true, - "validateRequestBody": true - }, - "no-validation": { - "validateRequestParameters": false, - "validateRequestBody": false - }, + "validateRequestBody": true, + "validateRequestParameters": true + }, "body-only": { - "validateRequestParameters": false, - "validateRequestBody": true - } - }, - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" - } - } + "validateRequestBody": true, + "validateRequestParameters": false + }, + "no-validation": { + "validateRequestBody": false, + "validateRequestParameters": false + }, + "params-only": { + "validateRequestBody": false, + "validateRequestParameters": true } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "HtmlFunctionOnlyBodyDefinitionFalseRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf186539e09": { + "Properties": { + "Description": "RestApi deployment id: f186539e0968ebab9c817becf503f8f5f6d029fd", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentf186539e09" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionMixinValidation": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionMixinValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionMixinValidationGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionMixinValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionMixinValidationRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalse": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionNoValidation": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionOnlyRequestDefinitionFalseRole", + "HtmlFunctionNoValidationRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionNoValidationGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNoValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionNoValidationRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionNotDefinedValidation": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionNotDefinedValidationRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionNoValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionNoValidation" - }, + "Ref": "HtmlFunctionNotDefinedValidation" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionNotDefinedValidationRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionOnlyRequestDefinition" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } - }, - "HtmlApiDeploymentf186539e09": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f186539e0968ebab9c817becf503f8f5f6d029fd", - "StageName": "Stage" - } - }, - "HtmlFunctionOnlyRequestDefinition": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionOnlyRequestDefinitionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionNoValidation": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyBodyDefinition": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionNoValidationRole", + "HtmlFunctionOnlyBodyDefinitionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinition": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyBodyDefinitionFalse": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionOnlyBodyDefinitionRole", + "HtmlFunctionOnlyBodyDefinitionFalseRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" - }, + "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionNoValidationRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyBodyDefinitionFalseRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionMixinValidationGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionMixinValidation" - }, + "Ref": "HtmlFunctionOnlyBodyDefinition" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionMixinValidation": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyBodyDefinitionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyRequestDefinition": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionMixinValidationRole", + "HtmlFunctionOnlyRequestDefinitionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinitionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyRequestDefinitionFalse": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyRequestDefinitionFalseRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" - }, + "Ref": "HtmlFunctionOnlyRequestDefinition" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionOnlyRequestDefinitionRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunctionOnlyBodyDefinition" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_request_model_with_validator_openapi_3.json b/tests/translator/output/aws-us-gov/api_request_model_with_validator_openapi_3.json index 83fd018130..168c142ea0 100644 --- a/tests/translator/output/aws-us-gov/api_request_model_with_validator_openapi_3.json +++ b/tests/translator/output/aws-us-gov/api_request_model_with_validator_openapi_3.json @@ -1,76 +1,27 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymente5c2c7da3d" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "schemas": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { "/": { "get": { @@ -81,82 +32,131 @@ "$ref": "#/components/schemas/user" } } - }, + }, "required": true - }, + }, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" } - }, - "x-amazon-apigateway-request-validator": "body-and-params", - "responses": {} + }, + "x-amazon-apigateway-request-validator": "body-and-params" } } - }, - "openapi": "3.0", - "components": { - "schemas": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" - } - } - } - } - }, + }, "x-amazon-apigateway-request-validators": { "body-and-params": { - "validateRequestParameters": true, - "validateRequestBody": true + "validateRequestBody": true, + "validateRequestParameters": true } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "HtmlApiDeploymente5c2c7da3d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: e5c2c7da3d6e36d656af91f88bf7d1e773111a32", "RestApiId": { "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: e5c2c7da3d6e36d656af91f88bf7d1e773111a32" - } - }, + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymente5c2c7da3d" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi.json b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi.json index 761bd64be0..380d1636eb 100644 --- a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi.json +++ b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi.json @@ -1,168 +1,110 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment4a021ff84a" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, "info": { "title": { "Fn::Sub": "${AWS::StackName}-Api" } }, + "openapi": "3.0", "paths": { "/post": { "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -171,13 +113,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -186,57 +133,52 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] - } - }, - { - "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "1.0", "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, + "uri": "https://www.otherURI.co/" + } + } + }, + { "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -245,13 +187,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -260,73 +207,126 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiDeployment4a021ff84a": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 4a021ff84ad1127bd2e89e8288160946fbf1609a", "RestApiId": { "Ref": "MyApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment4a021ff84a" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_else_case.json b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_else_case.json index e674202908..e582560f14 100644 --- a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_else_case.json +++ b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_else_case.json @@ -1,178 +1,110 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentd912e8ed8f" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyApiDeploymentd912e8ed8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: d912e8ed8f7e209db2137ff3ce50c6bbe2acc72a", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, "info": { "title": { "Fn::Sub": "${AWS::StackName}-Api" } }, + "openapi": "3.0", "paths": { "/post": { "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +113,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,9 +133,12 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } } }, { @@ -206,56 +146,116 @@ } ] } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentd912e8ed8f": { + "Properties": { + "Description": "RestApi deployment id: d912e8ed8f7e209db2137ff3ce50c6bbe2acc72a", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentd912e8ed8f" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_then_case.json b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_then_case.json index a6fca1b448..64ca201b9e 100644 --- a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_then_case.json +++ b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_openapi_no_value_then_case.json @@ -1,33 +1,175 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { + "MyApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyLambdaAuthUpdated": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerResultTtlInSeconds": 37, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "Fn::If": [ + "FalseCondition", + { + "Ref": "AWS::NoValue" + }, + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": { + "Fn::Join": [ + ",", + [ + "www.amazon.com", + "www.google.com" + ] + ] + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + ] + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, "MyApiDeployment7a57336b93": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 7a57336b93896aa7a8c72e034a952fc1afc9a482", "RestApiId": { "Ref": "MyApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -47,10 +189,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment7a57336b93" @@ -59,10 +201,10 @@ "Ref": "MyApi" }, "StageName": "dev" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -82,13 +224,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -101,7 +242,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -112,150 +254,8 @@ "Value": "SAM" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "Fn::If": [ - "FalseCondition", - { - "Ref": "AWS::NoValue" - }, - { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, - "options": { - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": { - "Fn::Join": [ - ",", - [ - "www.amazon.com", - "www.google.com" - ] - ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, - "summary": "CORS support", - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ], - "consumes": [ - "application/json" - ] - } - } - ] - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaAuthUpdated": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 37, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger.json b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger.json index 8c586525c3..b041b92fb5 100644 --- a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger.json +++ b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger.json @@ -1,111 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment12d57c142f" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -118,51 +29,43 @@ "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -171,13 +74,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -186,57 +94,52 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] - } - }, - { - "post": { "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "1.0", "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, + "uri": "https://www.otherURI.co/" + } + } + }, + { "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -245,13 +148,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -260,27 +168,29 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -295,36 +205,126 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiDeployment12d57c142f": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 12d57c142fc2514cd1e8308cc6067205bd6b1923", "RestApiId": { "Ref": "MyApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment12d57c142f" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_else_case.json b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_else_case.json index 3ccc2ccf0c..6c15629397 100644 --- a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_else_case.json +++ b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_else_case.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymente8d14e9a46" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiDeploymente8d14e9a46": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: e8d14e9a46ec615e88fcee45775372485f8ed243", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -128,51 +29,43 @@ "Fn::If": [ "FalseCondition", { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otherURI.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -181,13 +74,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -196,9 +94,12 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otherURI.co/" + } } }, { @@ -207,19 +108,18 @@ ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -234,26 +134,126 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymente8d14e9a46": { + "Properties": { + "Description": "RestApi deployment id: e8d14e9a46ec615e88fcee45775372485f8ed243", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymente8d14e9a46" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_then_case.json b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_then_case.json index 6467820e59..66bacd38ef 100644 --- a/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_then_case.json +++ b/tests/translator/output/aws-us-gov/api_rest_paths_with_if_condition_swagger_no_value_then_case.json @@ -1,121 +1,22 @@ { "AWSTemplateFormatVersion": "2010-09-09", - "Description": "sam-app\nSample SAM Template for sam-app\n", "Conditions": { - "TrueCondition": { + "FalseCondition": { "Fn::Equals": [ true, - true + false ] }, - "FalseCondition": { + "TrueCondition": { "Fn::Equals": [ true, - false + true ] } }, + "Description": "sam-app\nSample SAM Template for sam-app\n", "Resources": { - "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment9b1182e52b" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "dev" - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyApiDeployment9b1182e52b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 9b1182e52bcd94d4984db4a1844447cbc60968e5", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { @@ -131,51 +32,43 @@ "Ref": "AWS::NoValue" }, { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "MyLambdaAuthUpdated": [] - }, - { - "api_key": [] - } - ] - }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } }, - "produces": [ - "application/json" + "security": [ + { + "MyLambdaAuthUpdated": [] + }, + { + "api_key": [] + } ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ ",", @@ -184,13 +77,18 @@ "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + }, + "post": { "security": [ { "MyLambdaAuthUpdated": [] @@ -199,27 +97,29 @@ "api_key": [] } ], - "consumes": [ - "application/json" - ] + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } } } ] } }, - "swagger": "2.0", "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, "MyLambdaAuthUpdated": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, "authorizerResultTtlInSeconds": 37, "authorizerUri": { "Fn::Sub": [ @@ -234,26 +134,126 @@ } ] }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - } + "type": "token" }, "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment9b1182e52b": { + "Properties": { + "Description": "RestApi deployment id: 9b1182e52bcd94d4984db4a1844447cbc60968e5", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaAuthUpdatedAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment9b1182e52b" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_swagger_integration_with_ref_intrinsic_api_id.json b/tests/translator/output/aws-us-gov/api_swagger_integration_with_ref_intrinsic_api_id.json index 5bea6d006b..88acf734b9 100644 --- a/tests/translator/output/aws-us-gov/api_swagger_integration_with_ref_intrinsic_api_id.json +++ b/tests/translator/output/aws-us-gov/api_swagger_integration_with_ref_intrinsic_api_id.json @@ -1,172 +1,172 @@ { "Resources": { - "HtmlApiDeployment0ab6cda881": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: 0ab6cda8810d586361f754db101bd7e456f7f561", - "StageName": "Stage" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment0ab6cda881" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "HtmlApi" - } - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "123456" + ] + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/", + "execute-api:/${__Stage__}/GET/", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": { - "AWS": [ - "123456" - ] - } - } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } + ] + }, + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeployment0ab6cda881": { + "Properties": { + "Description": "RestApi deployment id: 0ab6cda8810d586361f754db101bd7e456f7f561", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment0ab6cda881" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "HtmlApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_swagger_integration_with_string_api_id.json b/tests/translator/output/aws-us-gov/api_swagger_integration_with_string_api_id.json index d98e0a141a..594caa990c 100644 --- a/tests/translator/output/aws-us-gov/api_swagger_integration_with_string_api_id.json +++ b/tests/translator/output/aws-us-gov/api_swagger_integration_with_string_api_id.json @@ -1,170 +1,170 @@ { "Resources": { - "HtmlApiDeployment0ab6cda881": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: 0ab6cda8810d586361f754db101bd7e456f7f561", - "StageName": "Stage" - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeployment0ab6cda881" - }, - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Prod" - } - }, - "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HtmlApi" - } - ] - } - } - }, "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "123456" + ] + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/", + "execute-api:/${__Stage__}/GET/", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": { - "AWS": [ - "123456" - ] - } - } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } + ] + }, + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeployment0ab6cda881": { + "Properties": { + "Description": "RestApi deployment id: 0ab6cda8810d586361f754db101bd7e456f7f561", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment0ab6cda881" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "HtmlFunctionRole", + "HtmlFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HtmlFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_access_log_setting.json b/tests/translator/output/aws-us-gov/api_with_access_log_setting.json index 0c0a9d6762..e174acaa86 100644 --- a/tests/translator/output/aws-us-gov/api_with_access_log_setting.json +++ b/tests/translator/output/aws-us-gov/api_with_access_log_setting.json @@ -1,7 +1,49 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "AccessLogSetting": { + "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", + "Format": "$context.requestId" + }, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,153 +59,84 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "AccessLogSetting": { - "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", - "Format": "$context.requestId" - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment5b2cb4ba8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ImplicitApiFunctionRole": { "Properties": { - "AccessLogSetting": { - "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", - "Format": "$context.requestId" - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -177,7 +150,34 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5b2cb4ba8f": { + "Properties": { + "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "AccessLogSetting": { + "DestinationArn": "arn:aws:logs:us-west-2:012345678901/API-Gateway-Execution-Logs_0123456789/prod:log-stream:12345678910", + "Format": "$context.requestId" + }, + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_any_method_in_swagger.json b/tests/translator/output/aws-us-gov/api_with_any_method_in_swagger.json index 9bd62ca944..6726375ad8 100644 --- a/tests/translator/output/aws-us-gov/api_with_any_method_in_swagger.json +++ b/tests/translator/output/aws-us-gov/api_with_any_method_in_swagger.json @@ -1,27 +1,12 @@ { "Resources": { - "MyApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment0ebc8893a3" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": { - "Ref": "Stage" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ "HttpApiFunctionRole", @@ -31,38 +16,16 @@ "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -75,110 +38,122 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiDeployment0ebc8893a3": { - "Type": "AWS::ApiGateway::Deployment", + "HttpApiFunctionSimpleCasePermission": { "Properties": { - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" }, - "Description": "RestApi deployment id: 0ebc8893a30055fb944d26720dc8ffddacc6d27d", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "LambdaAuthorizer": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": null + } + ] + }, + "identitySource": "method.request.header.Authorization", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, "info": { "title": { "Fn::Sub": "${AWS::StackName}-Api" } }, + "openapi": "3.0", "paths": { "$default": { "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, "isDefaultRoute": true, + "responses": {}, "security": [ { "LambdaAuthorizer": [] } ], - "responses": {} + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } }, "/": { "any": { + "security": [ + { + "LambdaAuthorizer": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "ANY", + "payloadFormatVersion": "1.0", "type": "http_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, + "uri": "https://www.alphavantage.co/" + } + }, + "get": { + "responses": {}, "security": [ { "LambdaAuthorizer": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", + "payloadFormatVersion": "2.0", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "LambdaAuthorizer": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "LambdaAuthorizer": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": null - } - ] } - }, - "x-amazon-apigateway-authtype": "custom" + } } } } @@ -191,7 +166,32 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment0ebc8893a3": { + "Properties": { + "Description": "RestApi deployment id: 0ebc8893a30055fb944d26720dc8ffddacc6d27d", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment0ebc8893a3" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": { + "Ref": "Stage" + } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_apikey_default_override.json b/tests/translator/output/aws-us-gov/api_with_apikey_default_override.json index cdab211aa9..2567f5518e 100644 --- a/tests/translator/output/aws-us-gov/api_with_apikey_default_override.json +++ b/tests/translator/output/aws-us-gov/api_with_apikey_default_override.json @@ -1,59 +1,94 @@ { "Resources": { - "MyApiWithAuthDeployment084855ab6d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAuth" - }, - "Description": "RestApi deployment id: 084855ab6d04ef5b762ac75de403810cd5f0c166", - "StageName": "Stage" - } - }, - "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithAuth": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredTrue" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyDefault": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredDefault.Arn}/invocations" + } + } + } + }, + "/ApiKeyFalse": { + "get": { + "responses": {}, + "security": [], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredFalse.Arn}/invocations" + } + } + } + }, + "/ApiKeyTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" + } + } } } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionWithApiKeyRequiredFalseMyApiWithApiKeyRequiredFalsePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithAuthDeployment084855ab6d": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredFalse" + "Description": "RestApi deployment id: 084855ab6d04ef5b762ac75de403810cd5f0c166", + "RestApiId": { + "Ref": "MyApiWithAuth" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyFalse", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAuth" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithAuthDeployment084855ab6d" @@ -62,39 +97,16 @@ "Ref": "MyApiWithAuth" }, "StageName": "Prod" - } - }, - "MyFunctionWithApiKeyRequiredTrue": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithApiKeyRequiredTrueRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + }, + "Type": "AWS::ApiGateway::Stage" }, "MyFunctionWithApiKeyRequiredDefault": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionWithApiKeyRequiredDefaultRole", @@ -104,41 +116,71 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionWithApiKeyRequiredDefaultMyApiWithApiKeyRequiredDefaultPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionWithApiKeyRequiredDefault" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyDefault", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithApiKeyRequiredDefaultRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionWithApiKeyRequiredFalse": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionWithApiKeyRequiredFalseRole", @@ -148,26 +190,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredFalseMyApiWithApiKeyRequiredFalsePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyFalse", + { + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredFalseRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,54 +233,68 @@ ] } } - ] - } - } - }, - "MyFunctionWithApiKeyRequiredDefaultRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithApiKeyRequiredTrue": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithApiKeyRequiredTrueRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredTrue" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApiWithAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredTrueRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -240,87 +307,20 @@ ] } } - ] - } - } - }, - "MyApiWithAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyFalse": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredFalse.Arn}/invocations" - } - }, - "security": [], - "responses": {} - } - }, - "/ApiKeyTrue": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - }, - "/ApiKeyDefault": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredDefault.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + ], + "Version": "2012-10-17" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_apikey_required.json b/tests/translator/output/aws-us-gov/api_with_apikey_required.json index c2b004cdbe..4fcb9b779b 100644 --- a/tests/translator/output/aws-us-gov/api_with_apikey_required.json +++ b/tests/translator/output/aws-us-gov/api_with_apikey_required.json @@ -1,7 +1,93 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/ApiKeyRequiredTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + }, + "/any/ApiKeyRequiredTrue": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment21dacab558": { + "Properties": { + "Description": "RestApi deployment id: 21dacab558603b40cc8f8528fd85cc226e8769c5", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment21dacab558" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithApiKeyRequired": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +107,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithApiKeyRequiredRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +119,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +128,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +140,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,94 +149,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithApiKeyRequiredRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyRequiredTrue": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/ApiKeyRequiredTrue": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithoutAuthDeployment21dacab558": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 21dacab558603b40cc8f8528fd85cc226e8769c5", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment21dacab558" - }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_apikey_required_openapi_3.json b/tests/translator/output/aws-us-gov/api_with_apikey_required_openapi_3.json index 4f3bd96f26..aabce940ef 100644 --- a/tests/translator/output/aws-us-gov/api_with_apikey_required_openapi_3.json +++ b/tests/translator/output/aws-us-gov/api_with_apikey_required_openapi_3.json @@ -1,7 +1,94 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/ApiKeyRequiredTrue": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + }, + "/any/ApiKeyRequiredTrue": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment9d2e3e35ec": { + "Properties": { + "Description": "RestApi deployment id: 9d2e3e35ec48e8d035a3fcd56a245a84688c2fda", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment9d2e3e35ec" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithApiKeyRequired": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +108,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithApiKeyRequiredRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +120,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +129,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithApiKeyRequiredMyApiWithApiKeyRequiredPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +141,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/ApiKeyRequiredTrue", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyRequiredTrue", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,95 +150,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithApiKeyRequiredRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/ApiKeyRequiredTrue": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/ApiKeyRequiredTrue": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequired.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithoutAuthDeployment9d2e3e35ec": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 9d2e3e35ec48e8d035a3fcd56a245a84688c2fda", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - } - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment9d2e3e35ec" + ], + "Version": "2012-10-17" }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_apikey_source.json b/tests/translator/output/aws-us-gov/api_with_apikey_source.json index 10e8478755..2de5dcdac0 100644 --- a/tests/translator/output/aws-us-gov/api_with_apikey_source.json +++ b/tests/translator/output/aws-us-gov/api_with_apikey_source.json @@ -1,77 +1,77 @@ { "Resources": { - "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionWithApiKeyRequiredTrue" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", - { - "__ApiId__": { - "Ref": "MyApiWithAuthSource" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithAuthSource": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "ApiKeySourceType": "AUTHORIZER", "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/ApiKeyTrue": { "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithApiKeyRequiredTrue.Arn}/invocations" } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "api_key": { - "type": "apiKey", + "in": "header", "name": "x-api-key", - "in": "header" + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] }, - "ApiKeySourceType": "AUTHORIZER" - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAuthSourceDeployment9bfe55913d": { + "Properties": { + "Description": "RestApi deployment id: 9bfe55913df8648e4e4fa59c5a88e49ee8f6b5b7", + "RestApiId": { + "Ref": "MyApiWithAuthSource" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAuthSourceProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAuthSourceDeployment9bfe55913d" + }, + "RestApiId": { + "Ref": "MyApiWithAuthSource" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyFunctionWithApiKeyRequiredTrue": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -91,23 +91,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithAuthSourceDeployment9bfe55913d": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithApiKeyRequiredTrueMyApiWithApiKeyRequiredTruePermissionProd": { "Properties": { - "Description": "RestApi deployment id: 9bfe55913df8648e4e4fa59c5a88e49ee8f6b5b7", - "RestApiId": { - "Ref": "MyApiWithAuthSource" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithApiKeyRequiredTrue" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/ApiKeyTrue", + { + "__ApiId__": { + "Ref": "MyApiWithAuthSource" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithApiKeyRequiredTrueRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -120,7 +130,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -131,19 +142,8 @@ "Value": "SAM" } ] - } - }, - "MyApiWithAuthSourceProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAuthSourceDeployment9bfe55913d" - }, - "RestApiId": { - "Ref": "MyApiWithAuthSource" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_auth_all_maximum.json b/tests/translator/output/aws-us-gov/api_with_auth_all_maximum.json index 9cc7479c5b..5bd524e645 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_all_maximum.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_all_maximum.json @@ -1,331 +1,17 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { @@ -334,150 +20,156 @@ { "api_key": [] } - ] - } - }, - "/any/noauth": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/cognitomultiple": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/users": { - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/default": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyCognitoAuth": [] }, { "api_key": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdarequest": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - }, - "patch": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatoken": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + "MyLambdaTokenAuth": [] }, { "api_key": [] } - ] - }, - "delete": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatokennone": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] }, { "api_key": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/noauth": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuth": [] + "NONE": [] }, { "api_key": [] } - ] - } - }, - "/any/cognitomultiple": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/users": { + "delete": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - } - }, - "/any/lambdatoken": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "get": { "responses": {}, "security": [ { @@ -486,18 +178,16 @@ { "api_key": [] } - ] - } - }, - "/any/lambdatokennone": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "patch": { "responses": {}, "security": [ { @@ -506,38 +196,34 @@ { "api_key": [] } - ] - } - }, - "/any/lambdarequest": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/any/default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { @@ -546,45 +232,52 @@ { "api_key": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "MyAuthorizationHeader", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "MyAuthorizationHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", + "identityValidationExpression": "myauthvalidationexpression", "providerARNs": [ "arn:aws:1" ], - "identityValidationExpression": "myauthvalidationexpression" - } + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, "MyCognitoAuthMultipleUserPools": { - "type": "apiKey", - "name": "MyAuthorizationHeader2", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "MyAuthorizationHeader2", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", + "identityValidationExpression": "myauthvalidationexpression2", "providerARNs": [ "arn:aws:2", "arn:aws:3" ], - "identityValidationExpression": "myauthvalidationexpression2" - } + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "MyCustomAuthHeader", + "MyLambdaRequestAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -593,18 +286,18 @@ } ] }, - "authorizerResultTtlInSeconds": 20, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - } + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "type": "apiKey", - "name": "Authorization", + "MyLambdaTokenAuth": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -613,16 +306,17 @@ } ] }, - "authorizerResultTtlInSeconds": 0 - } + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", + "MyLambdaTokenAuthNoneFunctionInvokeRole": { "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -631,103 +325,409 @@ } ] }, - "authorizerResultTtlInSeconds": 0, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4" + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment275e8e0d8c": { + "Properties": { + "Description": "RestApi deployment id: 275e8e0d8cf3a111a995e674cad920e51ff02de7", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment275e8e0d8c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment275e8e0d8c": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 275e8e0d8cf3a111a995e674cad920e51ff02de7", - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithDefaultAuthorizerPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment275e8e0d8c" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "RestApiId": { - "Ref": "MyApi" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_auth_all_maximum_openapi_3.json b/tests/translator/output/aws-us-gov/api_with_auth_all_maximum_openapi_3.json index d5aef29ace..7bde38e22d 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_all_maximum_openapi_3.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_all_maximum_openapi_3.json @@ -1,330 +1,112 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", - { - "__ApiId__": { - "Ref": "MyApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApi": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", - { - "__ApiId__": { - "Ref": "MyApi" + "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", - { - "__ApiId__": { - "Ref": "MyApi" + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" }, - "__Stage__": "*" + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { @@ -333,150 +115,156 @@ { "api_key": [] } - ] - } - }, - "/any/noauth": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/cognitomultiple": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/users": { - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/default": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyCognitoAuth": [] }, { "api_key": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdarequest": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - }, - "patch": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatoken": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + "MyLambdaTokenAuth": [] }, { "api_key": [] } - ] - }, - "delete": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/lambdatokennone": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] }, { "api_key": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/any/noauth": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { - "MyCognitoAuth": [] + "NONE": [] }, { "api_key": [] } - ] - } - }, - "/any/cognitomultiple": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + } + }, + "/users": { + "delete": { "responses": {}, "security": [ { - "MyCognitoAuthMultipleUserPools": [] + "MyLambdaRequestAuth": [] }, { "api_key": [] } - ] - } - }, - "/any/lambdatoken": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "get": { "responses": {}, "security": [ { @@ -485,18 +273,16 @@ { "api_key": [] } - ] - } - }, - "/any/lambdatokennone": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "patch": { "responses": {}, "security": [ { @@ -505,38 +291,34 @@ { "api_key": [] } - ] - } - }, - "/any/lambdarequest": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyCognitoAuthMultipleUserPools": [] }, { "api_key": [] } - ] - } - }, - "/any/default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { @@ -545,190 +327,408 @@ { "api_key": [] } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment0cb1804921": { + "Properties": { + "Description": "RestApi deployment id: 0cb1804921207c455f8eaaf3c704ecee88ec286f", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment0cb1804921" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "MyAuthorizationHeader", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - "arn:aws:1" - ], - "identityValidationExpression": "myauthvalidationexpression" - } - }, - "MyCognitoAuthMultipleUserPools": { - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "identityValidationExpression": "myauthvalidationexpression2" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognitomultiple", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "MyCustomAuthHeader", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 20, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 0 - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/default", + { + "__ApiId__": { + "Ref": "MyApi" }, - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerResultTtlInSeconds": 0, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4" - } + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithDefaultAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + { + "__ApiId__": { + "Ref": "MyApi" }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } + "__Stage__": "*" } - } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdarequest", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaRequestAuthorizerPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment0cb1804921": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionWithLambdaTokenAuthorizerAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 0cb1804921207c455f8eaaf3c704ecee88ec286f", - "RestApiId": { - "Ref": "MyApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatoken", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment0cb1804921" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "RestApiId": { - "Ref": "MyApi" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithLambdaTokenNoneAuthorizerAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambdatokennone", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenNoneAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/noauth", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": "arn:aws", + "FunctionName": { + "Ref": "MyFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json b/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json index 16b4cfc027..42f39831c6 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_all_minimum.json @@ -1,57 +1,55 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { + "/any/cognito": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { + "responses": {}, "security": [ { "MyCognitoAuth": [] } ], - "responses": {} - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -65,7 +63,8 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -75,98 +74,82 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithCognitoAuthDeployment492f1347b1": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment468dce6129" - }, + "Description": "RestApi deployment id: 492f1347b1194457232f0e99ced4a86954fdeec9", "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Ref": "MyApiWithCognitoAuth" }, - "StageName": "Prod" - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiWithCognitoAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment492f1347b1" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/any/lambda-request": { "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-request": { + "get": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } ], - "responses": {} - } - }, - "/lambda-request": { - "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyLambdaRequestAuth": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -179,11 +162,14 @@ } } ] - } + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -193,216 +179,105 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithCognitoAuthDeployment492f1347b1": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiWithLambdaRequestAuthDeployment468dce6129": { "Properties": { + "Description": "RestApi deployment id: 468dce61296ac92bf536be6fc55751d9553dbc4b", "RestApiId": { - "Ref": "MyApiWithCognitoAuth" + "Ref": "MyApiWithLambdaRequestAuth" }, - "Description": "RestApi deployment id: 492f1347b1194457232f0e99ced4a86954fdeec9", "StageName": "Stage" - } - }, - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "Schema": [ - { - "AttributeDataType": "String", - "Required": false, - "Name": "email" - } - ] - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { "Fn::GetAtt": [ - "MyAuthFnRole", + "MyAuthFn", "Arn" ] }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaRequestAuth" } } ] } - } - }, - "MyApiWithNotCachedLambdaRequestAuthDeploymentd3b8858811": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" - }, - "Description": "RestApi deployment id: d3b8858811d6c42be45490ba4d1ca059821cf4fd", - "StageName": "Stage" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } - }, - "MyApiWithLambdaTokenAuthDeployment5f3dce4e5c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "Description": "RestApi deployment id: 5f3dce4e5c196ff885a155dd8cc0ffeebd5b93b1", - "StageName": "Stage" - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment492f1347b1" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithNotCachedLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiWithLambdaRequestAuthProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuthDeploymentd3b8858811" + "Ref": "MyApiWithLambdaRequestAuthDeployment468dce6129" }, "RestApiId": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" + "Ref": "MyApiWithLambdaRequestAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithNotCachedLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaTokenAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/not-cached-lambda-request": { - "get": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, "security": [ { - "MyLambdaRequestAuth": [] + "MyLambdaTokenAuth": [] } ], - "responses": {} + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaRequestAuth": { + "MyLambdaTokenAuth": { "in": "header", + "name": "Authorization", "type": "apiKey", - "name": "Unused", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -415,11 +290,13 @@ } } ] - } + }, + "type": "token" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -429,169 +306,89 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } - } - ] - } - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthDeployment5f3dce4e5c": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "Description": "RestApi deployment id: 5f3dce4e5c196ff885a155dd8cc0ffeebd5b93b1", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ "MyAuthFn", "Arn" ] }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" - }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithLambdaTokenAuth" } } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithLambdaTokenAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment5f3dce4e5c" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithNotCachedLambdaRequestAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { + "/not-cached-lambda-request": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] } ], - "responses": {} - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaTokenAuth": { + "MyLambdaRequestAuth": { "in": "header", + "name": "Unused", "type": "apiKey", - "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -604,11 +401,13 @@ } } ] - } + }, + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -618,19 +417,29 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithNotCachedLambdaRequestAuthDeploymentd3b8858811": { + "Properties": { + "Description": "RestApi deployment id: d3b8858811d6c42be45490ba4d1ca059821cf4fd", + "RestApiId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithNotCachedLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Fn::GetAtt": [ "MyAuthFn", "Arn" ] }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", @@ -641,44 +450,47 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFnLambdaNotCachedRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiWithNotCachedLambdaRequestAuthProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFn" + "DeploymentId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuthDeploymentd3b8858811" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-cached-lambda-request", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithNotCachedLambdaRequestAuth" - } - } - ] - } - } + "RestApiId": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaRequestAuthDeployment468dce6129": { - "Type": "AWS::ApiGateway::Deployment", + "MyAuthFn": { "Properties": { - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "Description": "RestApi deployment id: 468dce61296ac92bf536be6fc55751d9553dbc4b", - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -691,39 +503,28 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment5f3dce4e5c" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::IAM::Role" }, "MyFn": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFnRole", @@ -733,11 +534,210 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaNotCachedRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-cached-lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithNotCachedLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaRequestPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenAnyMethodPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_auth_all_minimum_openapi.json b/tests/translator/output/aws-us-gov/api_with_auth_all_minimum_openapi.json index bcccf7104a..bc01e4ff51 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_all_minimum_openapi.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_all_minimum_openapi.json @@ -1,348 +1,94 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucketname", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucketname", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/cognito": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "/any/cognito": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyCognitoAuth": [] - } - ] - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - { - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - } - ] + } + } + } + }, + "/cognito": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } } } } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeploymentd15cd5215f": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: d15cd5215f8dc24b832be6e0143c03a7226ffbeb", "RestApiId": { "Ref": "MyApiWithCognitoAuth" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeploymentd15cd5215f" @@ -351,64 +97,148 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/lambda-token": { - "get": { + "/any/lambda-request": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-request": { + "get": { "responses": {}, "security": [ { - "MyLambdaTokenAuth": [] + "MyLambdaRequestAuth": [] } - ] - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {}, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ] + } } } - }, - "openapi": "3.0.1", + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeployment2866a2663d": { + "Properties": { + "Description": "RestApi deployment id: 2866a2663d620ea5e87834fa7ade690f394dd9a1", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeployment2866a2663d" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { "components": { "securitySchemes": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -421,194 +251,364 @@ } } ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } } } } } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithLambdaTokenAuthDeployment81ca64a86a": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 81ca64a86a839b7e8f545ef75080e4782b938375", "RestApiId": { "Ref": "MyApiWithLambdaTokenAuth" } - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment81ca64a86a" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucketname", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFn": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment81ca64a86a" + "Code": { + "S3Bucket": "bucketname", + "S3Key": "thumbnails.zip" }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnCognitoPermissionProd": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - }, - "/any/lambda-request": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeployment2866a2663d": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Description": "RestApi deployment id: 2866a2663d620ea5e87834fa7ade690f394dd9a1", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeployment2866a2663d" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" + "Ref": "MyFn" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnLambdaTokenPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_auth_and_conditions_all_max.json b/tests/translator/output/aws-us-gov/api_with_auth_and_conditions_all_max.json index 75a72a5d6c..061eb867f0 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_and_conditions_all_max.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_and_conditions_all_max.json @@ -2,325 +2,283 @@ "Conditions": { "PathCondition": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment5d64bc1235" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "NONE": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } } - }, + }, "/users": { - "put": { + "delete": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, + }, + "get": { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + }, "patch": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, + }, "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "MyCognitoAuthMultipleUserPools": [] } - ], - "responses": {} - }, - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} - }, - "delete": { + } + }, + "put": { "Fn::If": [ - "PathCondition", + "PathCondition", { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "PathCondition", + "PathCondition", { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithConditional.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", + "identityValidationExpression": "myauthvalidationexpression", "providerARNs": [ "arn:aws:1" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - } - }, + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, + }, + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment5d64bc1235": { + "Properties": { + "Description": "RestApi deployment id: 5d64bc123529878594c2e91158f7e6f22a4b7c78", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { "Ref": "MyApi" @@ -328,251 +286,293 @@ } ] } - } - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" } } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment5d64bc1235" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionWithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiDeployment5d64bc1235": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 5d64bc123529878594c2e91158f7e6f22a4b7c78", - "StageName": "Stage" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "MyFunctionWithConditional": { + "Condition": "PathCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithConditionalRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionWithConditionalRole": { + "Condition": "PathCondition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionWithConditionalWithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithConditionalWithDefaultAuthorizerPermissionProd": { + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionWithConditional" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionWithConditionalWithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunctionWithConditional" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithConditionalWithLambdaTokenAuthorizerPermissionProd": { + "Condition": "PathCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithConditional" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", { "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithConditionalWithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithLambdaTokenAuthorizerPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionWithConditional" - }, + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyFunctionWithConditionalRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithNoAuthorizerPermissionProd": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - }, - "Condition": "PathCondition" - }, - "MyFunctionWithConditional": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithConditionalRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "PathCondition" + }, + "Type": "AWS::Lambda::Permission" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_auth_no_default.json b/tests/translator/output/aws-us-gov/api_with_auth_no_default.json index e1b516b199..82e1688b84 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_no_default.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_no_default.json @@ -1,303 +1,46 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { + "/any/cognito": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + "/cognito": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -305,33 +48,36 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeployment7a90d1a343": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 7a90d1a343091df72446e32dd94c5229b9178d2c", "RestApiId": { "Ref": "MyApiWithCognitoAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeployment7a90d1a343" @@ -340,53 +86,168 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { - "get": { + "/any/lambda-request": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { + "httpMethod": "POST", "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-request": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } + } + } + } + }, + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] }, - "responses": {} + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeploymentd964e6a5ba": { + "Properties": { + "Description": "RestApi deployment id: d964e6a5ba7a5a0a4b49190e4f9100535f45d401", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeploymentd964e6a5ba" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, + "version": "1.0" + }, + "paths": { "/any/lambda-token": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { + "httpMethod": "POST", "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } + } + }, + "/lambda-token": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, - "responses": {} + } } } }, "securityDefinitions": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -399,183 +260,322 @@ } } ] - } + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaTokenAuthDeployment094f29ed11": { + "Properties": { + "Description": "RestApi deployment id: 094f29ed11748846f0541bbcba9b2e67a14a9724", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment094f29ed11" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthDeployment094f29ed11": { - "Type": "AWS::ApiGateway::Deployment", + "MyFn": { "Properties": { - "Description": "RestApi deployment id: 094f29ed11748846f0541bbcba9b2e67a14a9724", - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment094f29ed11" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any/lambda-request": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "securityDefinitions": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeploymentd964e6a5ba": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "Description": "RestApi deployment id: d964e6a5ba7a5a0a4b49190e4f9100535f45d401", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeploymentd964e6a5ba" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes.json b/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes.json index 1e0140f17f..c6dea7d8bf 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes.json @@ -1,407 +1,407 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/cognitowithauthnone": { + "/cognitoauthorizercopesoverwritten": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [] + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [] + "MyCognitoAuthWithDefaultScopes": [] } - ], - "responses": {} - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" ] } - ], - "responses": {} - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] + "MyDefaultCognitoAuth": [] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": {}, "security": [ { "MyDefaultCognitoAuth": [ - "overwritten.read", + "overwritten.read", "overwritten.write" ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - ], - "responses": {} + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ "arn:aws:2" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ "arn:aws:1" - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFnCognitoDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeploymentba9bfa6490": { + "Properties": { + "Description": "RestApi deployment id: ba9bfa649000ecc8dd6b649807472d08fe19ec39", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeploymentba9bfa6490" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFnCognitoDefaultScopesDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthDeploymentba9bfa6490": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: ba9bfa649000ecc8dd6b649807472d08fe19ec39", - "StageName": "Stage" - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoWithAuthNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeploymentba9bfa6490" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoWithAuthNonePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes_openapi.json b/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes_openapi.json index f1ed483faa..27c7284cc6 100644 --- a/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes_openapi.json +++ b/tests/translator/output/aws-us-gov/api_with_auth_with_default_scopes_openapi.json @@ -1,408 +1,408 @@ { "Resources": { "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuthWithDefaultScopes": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:2" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyDefaultCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/cognitowithauthnone": { + "/cognitoauthorizercopesoverwritten": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "responses": {}, "security": [ { - "NONE": [] + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [] + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesnone": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [] + "MyCognitoAuthWithDefaultScopes": [] } - ], - "responses": {} - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" ] } - ], - "responses": {} - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": {}, "security": [ { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] + "MyDefaultCognitoAuth": [] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": {}, "security": [ { "MyDefaultCognitoAuth": [ - "overwritten.read", + "overwritten.read", "overwritten.write" ] } - ], - "responses": {} - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": {}, "security": [ { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] + "NONE": [] } - ], - "responses": {} - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:2" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFnCognitoDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeploymentddb4f4405b": { + "Properties": { + "Description": "RestApi deployment id: ddb4f4405befb5324c4f18cdc69c3dd8489bc520", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeploymentddb4f4405b" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerWithDefaultScopesPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultAuthDefaultScopesNonePermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizerwithdefaultscopes", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultauthdefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeploymentddb4f4405b" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFnCognitoDefaultScopesDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesdefaultauthorizer", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnCognitoAuthorizerScopesOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesNonePermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitoauthorizercopesoverwritten", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoWithAuthNonePermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithCognitoAuthDeploymentddb4f4405b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: ddb4f4405befb5324c4f18cdc69c3dd8489bc520" - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFnCognitoDefaultScopesWithOverwrittenPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnCognitoWithAuthNonePermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFn" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitodefaultscopesoverwritten", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognitowithauthnone", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithCognitoAuth" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_aws_account_blacklist.json b/tests/translator/output/aws-us-gov/api_with_aws_account_blacklist.json index 79f06fdbb4..de94256a8d 100644 --- a/tests/translator/output/aws-us-gov/api_with_aws_account_blacklist.json +++ b/tests/translator/output/aws-us-gov/api_with_aws_account_blacklist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionAnyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,85 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -146,16 +149,16 @@ } ] } - ], + ] + }, + { + "Action": "execute-api:Invoke", + "Effect": "Deny", "Principal": { "AWS": [ "12345" ] - } - }, - { - "Effect": "Deny", - "Action": "execute-api:Invoke", + }, "Resource": [ { "Fn::Sub": [ @@ -165,38 +168,34 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment6a8eed6b70": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 6a8eed6b70acc4370ccf1562322a4119ecb9efbc", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment6a8eed6b70" @@ -205,7 +204,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_aws_account_whitelist.json b/tests/translator/output/aws-us-gov/api_with_aws_account_whitelist.json index 1d72b85425..3be330eab2 100644 --- a/tests/translator/output/aws-us-gov/api_with_aws_account_whitelist.json +++ b/tests/translator/output/aws-us-gov/api_with_aws_account_whitelist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionAnyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,85 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -146,16 +149,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "67890" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -165,16 +168,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "67890" - ] - } + ] }, { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": { + "AWS": [ + "12345" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -184,16 +187,16 @@ } ] } - ], - "Principal": { - "AWS": [ - "12345" - ] - } + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "67890" + ] + }, "Resource": [ { "Fn::Sub": [ @@ -203,38 +206,34 @@ } ] } - ], - "Principal": { - "AWS": [ - "67890" - ] - } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentada5c7703b": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: ada5c7703b63b68dc786a5c07c597a85018bd2cf", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentada5c7703b" @@ -243,7 +242,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_aws_iam_auth_overrides.json b/tests/translator/output/aws-us-gov/api_with_aws_iam_auth_overrides.json index 9ff1fa9ee4..7aaecbb891 100644 --- a/tests/translator/output/aws-us-gov/api_with_aws_iam_auth_overrides.json +++ b/tests/translator/output/aws-us-gov/api_with_aws_iam_auth_overrides.json @@ -1,945 +1,945 @@ { "Resources": { - "MyFunctionCustomInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionCustomInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionNoneAuth": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionNoneAuthRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionNullInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionNullInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeploymentc7d4214444" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } - }, - "MyFunctionWithoutAuthRole": { - "Type": "AWS::IAM::Role", + "MyApiWithAwsIamAuth": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/MyFunctionCustomInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::456::role/something-else", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCustomInvokeRole.Arn}/invocations" + } + } } - } - ] - } - } - }, - "MyFunctionCustomInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionCustomInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionCustomInvokeRole", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + }, + "/MyFunctionDefaultInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionDefaultInvokeRole.Arn}/invocations" + } + } } - } - ] - } - } - }, - "MyFunctionMyCognitoAuthAPI1PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionMyCognitoAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionMyCognitoAuth", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + }, + "/MyFunctionMyCognitoAuth": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionMyCognitoAuth.Arn}/invocations" + } + } + } + }, + "/MyFunctionNONEInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNONEInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionNoneAuth": { + "get": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoneAuth.Arn}/invocations" + } + } + } + }, + "/MyFunctionNullInvokeRole": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNullInvokeRole.Arn}/invocations" + } + } + } + }, + "/MyFunctionWithoutAuth": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::123:role/AUTH_AWS_IAM", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithoutAuth.Arn}/invocations" + } + } } } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + }, + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:cognito-idp:xxxxxxxxx" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "MyApiWithAwsIamAuthDeploymentc7d4214444": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: c7d4214444b325ee43f7a16744a5a74d01b268b2", "RestApiId": { "Ref": "MyApiWithAwsIamAuth" - }, - "Description": "RestApi deployment id: c7d4214444b325ee43f7a16744a5a74d01b268b2", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiWithAwsIamAuthNoCallerCredentials": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoCallerCredentials.Arn}/invocations" - } - }, + "get": { + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} - }, - "get": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCallerCredentialsOverride.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, + } + } + }, + "post": { + "responses": {}, "security": [ { "AWS_IAM": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoCallerCredentials.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFunctionWithoutAuthAPI2PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthNoCallerCredentialsDeployment673da6c5e9": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Description": "RestApi deployment id: 673da6c5e9481163e7b1cbf6d5604eb84cf64fd0", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthNoCallerCredentialsProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentialsDeployment673da6c5e9" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeploymentc7d4214444" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionCallerCredentialsOverride": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionCallerCredentialsOverrideRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionCallerCredentialsOverrideAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionWithoutAuth" - }, + "Ref": "MyFunctionCallerCredentialsOverride" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionWithoutAuth", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionDefaultInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionCallerCredentialsOverrideRole": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionDefaultInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionDefaultInvokeRole", + "AssumeRolePolicyDocument": { + "Statement": [ { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - ] - } - } - }, - "MyFunctionMyCognitoAuth": { - "Type": "AWS::Lambda::Function", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionCustomInvokeRole": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionMyCognitoAuthRole", + "MyFunctionCustomInvokeRoleRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRoleRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionCustomInvokeRoleAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionCustomInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionCustomInvokeRole", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionCustomInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionNONEInvokeRole": { - "Type": "AWS::Lambda::Function", + "MyFunctionDefaultInvokeRole": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNONEInvokeRoleRole", + "MyFunctionDefaultInvokeRoleRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoCallerCredentialsAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionDefaultInvokeRoleAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNoCallerCredentials" - }, + "Ref": "MyFunctionDefaultInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionDefaultInvokeRole", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - } + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNoneAuthRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionDefaultInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionCustomInvokeRoleRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionMyCognitoAuth": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionMyCognitoAuthRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionMyCognitoAuthAPI1PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionMyCognitoAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionMyCognitoAuth", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionMyCognitoAuthRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNONEInvokeRole": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNONEInvokeRoleRole", + "Arn" ] - } - } - }, - "MyFunctionCallerCredentialsOverrideAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNONEInvokeRoleAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionCallerCredentialsOverride" - }, + "Ref": "MyFunctionNONEInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNONEInvokeRole", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - } + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionCallerCredentialsOverride": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNONEInvokeRoleRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNoCallerCredentials": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionCallerCredentialsOverrideRole", + "MyFunctionNoCallerCredentialsRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNoCallerCredentialsAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionNoCallerCredentials" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNoCallerCredentialsRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionWithoutAuth": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionNoneAuth": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionWithoutAuthRole", + "MyFunctionNoneAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNullInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionNullInvokeRole" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNullInvokeRole", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } - } - ] - } - } - }, - "MyFunctionNONEInvokeRoleAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNoneAuthAPI3PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNONEInvokeRole" - }, + "Ref": "MyFunctionNoneAuth" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNONEInvokeRole", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNoneAuth", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyFunctionNoCallerCredentialsRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionNoneAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionDefaultInvokeRoleRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionCallerCredentialsOverrideRole": { - "Type": "AWS::IAM::Role", + "MyFunctionNullInvokeRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionNullInvokeRoleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionNullInvokeRoleAPI3PermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionNullInvokeRole" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNullInvokeRole", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionMyCognitoAuthRole": { - "Type": "AWS::IAM::Role", + "MyFunctionNullInvokeRoleRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyApiWithAwsIamAuthNoCallerCredentialsProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentialsDeployment673da6c5e9" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - }, - "StageName": "Prod" - } - }, - "MyFunctionDefaultInvokeRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionDefaultInvokeRoleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionNoCallerCredentials": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionWithoutAuth": { "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionNoCallerCredentialsRole", + "MyFunctionWithoutAuthRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/MyFunctionWithoutAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithoutAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNONEInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNONEInvokeRole.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionMyCognitoAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionMyCognitoAuth.Arn}/invocations" - } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } - }, - "/MyFunctionDefaultInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionDefaultInvokeRole.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionCustomInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionCustomInvokeRole.Arn}/invocations" - }, - "credentials": "arn:aws:iam::456::role/something-else" - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNullInvokeRole": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNullInvokeRole.Arn}/invocations" - } - }, - "security": [ - { - "AWS_IAM": [] - } - ], - "responses": {} - } - }, - "/MyFunctionNoneAuth": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionNoneAuth.Arn}/invocations" - } - }, - "security": [ - { - "NONE": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:cognito-idp:xxxxxxxxx" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "AWS_IAM": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyFunctionNoneAuthAPI3PermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithoutAuthAPI2PermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionNoneAuth" - }, + "Ref": "MyFunctionWithoutAuth" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionNoneAuth", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/MyFunctionWithoutAuth", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiWithAwsIamAuthNoCallerCredentialsDeployment673da6c5e9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthNoCallerCredentials" - }, - "Description": "RestApi deployment id: 673da6c5e9481163e7b1cbf6d5604eb84cf64fd0", - "StageName": "Stage" - } - }, - "MyFunctionNONEInvokeRoleRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithoutAuthRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain.json b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain.json index 8d04935fe7..cb40f36988 100644 --- a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain.json +++ b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain.json @@ -1,62 +1,19 @@ { "Parameters": { - "MyDomainName": { - "Default": "another-example.com", - "Type": "String" - }, "MyDomainCert": { - "Default": "another-api-arn", + "Default": "another-api-arn", + "Type": "String" + }, + "MyDomainName": { + "Default": "another-example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionAnotherGetPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/another/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyAnotherApi" - } - } - ] - } - } - }, "ApiGatewayDomainName23cdccdf9c": { - "Type": "AWS::ApiGateway::DomainName", "Properties": { - "CertificateArn": "my-api-cert-arn", + "CertificateArn": "my-api-cert-arn", + "DomainName": "api-example.com", "EndpointConfiguration": { "Types": [ "EDGE" @@ -66,356 +23,399 @@ "TruststoreUri": "my-api-truststore-uri", "TruststoreVersion": "my-api-truststore-version" }, - "SecurityPolicy": "TLS_1_2", - "DomainName": "api-example.com" - } - }, - "MyFunctionImplicitGetPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "MyAnotherApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyAnotherApiDeploymenteb8302ec1b" - }, - "RestApiId": { - "Ref": "MyAnotherApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment790a4e6aa6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 790a4e6aa6ad06f44702e52a66e5fec0cd96be99", - "StageName": "Stage" - } - }, - "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "ApiGatewayDomainNameeab65c1531": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } + "DomainName": "another-example.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - } - } - }, + }, + "RegionalCertificateArn": "another-api-arn" + }, + "Type": "AWS::ApiGateway::DomainName" + }, "MyAnotherApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "/another/get": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0.1" - }, + } + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyApigetBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyAnotherApiBasePathMapping": { "Properties": { - "BasePath": "get", "DomainName": { - "Ref": "ApiGatewayDomainName23cdccdf9c" - }, + "Ref": "ApiGatewayDomainNameeab65c1531" + }, "RestApiId": { - "Ref": "MyApi" - }, + "Ref": "MyAnotherApi" + }, "Stage": { - "Ref": "MyApiProdStage" + "Ref": "MyAnotherApiProdStage" } - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyAnotherApiDeploymenteb8302ec1b": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyApiDeploymentb34773e43a": { - "Type": "AWS::ApiGateway::Deployment", + "Description": "RestApi deployment id: eb8302ec1bd45ce6bb547e74633c4bbb3e503d4a", + "RestApiId": { + "Ref": "MyAnotherApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyAnotherApiProdStage": { "Properties": { + "DeploymentId": { + "Ref": "MyAnotherApiDeploymenteb8302ec1b" + }, "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: b34773e43ad9a98f27deed4374d3a49449abd947" - } - }, + "Ref": "MyAnotherApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get": { - "put": { + "/fetch": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/fetch": { - "post": { + }, + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0.1" - }, + } + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyAnotherApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentb34773e43a": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainNameeab65c1531" - }, + "Description": "RestApi deployment id: b34773e43ad9a98f27deed4374d3a49449abd947", "RestApiId": { - "Ref": "MyAnotherApi" - }, - "Stage": { - "Ref": "MyAnotherApiProdStage" + "Ref": "MyApi" } - } - }, - "ApiGatewayDomainNameeab65c1531": { - "Type": "AWS::ApiGateway::DomainName", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + "DeploymentId": { + "Ref": "MyApiDeploymentb34773e43a" + }, + "RestApiId": { + "Ref": "MyApi" }, - "RegionalCertificateArn": "another-api-arn", - "DomainName": "another-example.com" - } - }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyApifetchBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { - "BasePath": "fetch", + "BasePath": "fetch", "DomainName": { "Ref": "ApiGatewayDomainName23cdccdf9c" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApigetBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment790a4e6aa6" - }, + "BasePath": "get", + "DomainName": { + "Ref": "ApiGatewayDomainName23cdccdf9c" + }, "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "MyAnotherApiDeploymenteb8302ec1b": { - "Type": "AWS::ApiGateway::Deployment", + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { "Properties": { - "RestApiId": { - "Ref": "MyAnotherApi" - }, - "Description": "RestApi deployment id: eb8302ec1bd45ce6bb547e74633c4bbb3e503d4a" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAnotherGetPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentb34773e43a" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/another/get", + { + "__ApiId__": { + "Ref": "MyAnotherApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionApiPermissionProd": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainNameeab65c1531" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Stage": { - "Ref": "ServerlessRestApiProdStage" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionFetchPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitGetPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/implicit": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiBasePathMapping": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] + "DomainName": { + "Ref": "ApiGatewayDomainNameeab65c1531" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "Stage": { + "Ref": "ServerlessRestApiProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ServerlessRestApiDeployment790a4e6aa6": { + "Properties": { + "Description": "RestApi deployment id: 790a4e6aa6ad06f44702e52a66e5fec0cd96be99", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment790a4e6aa6" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_http.json b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_http.json index dff06df868..51302444b3 100644 --- a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_http.json +++ b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_http.json @@ -1,37 +1,21 @@ { "Parameters": { - "MyDomainName": { - "Default": "sam-example.com", - "Type": "String" - }, "MyDomainCert": { - "Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "Default": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "Type": "String" + }, + "MyDomainName": { + "Default": "sam-example.com", "Type": "String" } - }, + }, "Resources": { - "MyApibasicApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV22dbf35af54" - }, - "ApiMappingKey": "basic", - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, "ApiGatewayDomainNameV22dbf35af54": { - "Type": "AWS::ApiGatewayV2::DomainName", "Properties": { - "DomainName": "sam-example.com", + "DomainName": "sam-example.com", "DomainNameConfigurations": [ { - "CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", + "CertificateArn": "arn:aws:acm:us-east-1:123455353535:certificate/6c911401-620d-4d41-b89e-366c238bb2f3", "EndpointType": "REGIONAL", "SecurityPolicy": "TLS_1_2" } @@ -43,190 +27,206 @@ "Tags": { "httpapi:createdBy": "SAM" } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApibeginhereApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV22dbf35af54" - }, - "ApiMappingKey": "begin-here", - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RecordSetGroup1f4f569a7e": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { "Properties": { - "HostedZoneName": "sam-example.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV22dbf35af54", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV22dbf35af54", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "sam-example.com" - } - ] - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + } + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/basic": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], + }, "servers": [ { "x-amazon-apigateway-endpoint-configuration": { "disableExecuteApiEndpoint": true } } + ], + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApibasicApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "basic", + "DomainName": { + "Ref": "ApiGatewayDomainNameV22dbf35af54" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApibeginhereApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "begin-here", + "DomainName": { + "Ref": "ApiGatewayDomainNameV22dbf35af54" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "RecordSetGroup1f4f569a7e": { + "Properties": { + "HostedZoneName": "sam-example.com.", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV22dbf35af54", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV22dbf35af54", + "RegionalHostedZoneId" + ] + } + }, + "Name": "sam-example.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics.json b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics.json index 8d1fbf5bbb..142c16774d 100644 --- a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics.json +++ b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics.json @@ -2,18 +2,18 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { - "MyDomainCert": { - "Default": "another-api-arn", - "Type": "String" - }, "EndpointConf": { - "Default": "REGIONAL", + "Default": "REGIONAL", + "Type": "String" + }, + "MyDomainCert": { + "Default": "another-api-arn", "Type": "String" }, "MyMTLSUri": { @@ -24,326 +24,326 @@ "Default": "another-api-truststore-version", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "C1" - }, - "MyFunctionImplicitGetPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "C1" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment0294e6b48a" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "C1" - }, - "MyApifetchBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayDomainName9c93aac102": { + "Condition": "C1", "Properties": { - "BasePath": "fetch", "DomainName": { - "Ref": "ApiGatewayDomainName9c93aac102" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Fn::Sub": "example-us-gov-west-1.com" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "C1" - }, - "MyApigetBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "get", - "DomainName": { - "Ref": "ApiGatewayDomainName9c93aac102" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "ServerlessRestApiDeployment0294e6b48a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 0294e6b48a4d409ae8dbd2333cd092c27cbee6fe", - "StageName": "Stage" - }, - "Condition": "C1" - }, - "MyApiDeployment32e59613e2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 32e59613e2e02a1f1d264849167ea359f10342f0" - }, - "Condition": "C1" - }, + }, + "MutualTlsAuthentication": { + "TruststoreUri": "another-api-truststore-uri", + "TruststoreVersion": "another-api-truststore-version" + }, + "RegionalCertificateArn": "another-api-arn", + "SecurityPolicy": "TLS_1_2" + }, + "Type": "AWS::ApiGateway::DomainName" + }, "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "/get": { "Fn::If": [ - "C1", + "C1", { "put": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1" - }, + } + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment32e59613e2": { + "Condition": "C1", + "Properties": { + "Description": "RestApi deployment id: 32e59613e2e02a1f1d264849167ea359f10342f0", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "Condition": "C1", "Properties": { "DeploymentId": { "Ref": "MyApiDeployment32e59613e2" - }, + }, "RestApiId": { "Ref": "MyApi" - }, + }, "StageName": "Prod" - }, - "Condition": "C1" - }, - "ApiGatewayDomainName9c93aac102": { - "Type": "AWS::ApiGateway::DomainName", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApifetchBasePathMapping": { + "Condition": "C1", "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + "BasePath": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainName9c93aac102" }, - "MutualTlsAuthentication": { - "TruststoreUri": "another-api-truststore-uri", - "TruststoreVersion": "another-api-truststore-version" + "RestApiId": { + "Ref": "MyApi" }, - "SecurityPolicy": "TLS_1_2", - "RegionalCertificateArn": "another-api-arn", + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyApigetBasePathMapping": { + "Condition": "C1", + "Properties": { + "BasePath": "get", "DomainName": { - "Fn::Sub": "example-us-gov-west-1.com" + "Ref": "ApiGatewayDomainName9c93aac102" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyFunction": { + "Condition": "C1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionImplicitGetPermissionProd": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Condition": "C1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/implicit": { "Fn::If": [ - "C1", + "C1", { "post": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, - "Condition": "C1" - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment0294e6b48a": { + "Condition": "C1", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "C1" + "Description": "RestApi deployment id: 0294e6b48a4d409ae8dbd2333cd092c27cbee6fe", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment0294e6b48a" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics_http.json b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics_http.json index a54589ced9..50100de2ba 100644 --- a/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics_http.json +++ b/tests/translator/output/aws-us-gov/api_with_basic_custom_domain_intrinsics_http.json @@ -2,18 +2,18 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { - "MyDomainCert": { - "Default": "another-api-arn", - "Type": "String" - }, "EndpointConf": { - "Default": "REGIONAL", + "Default": "REGIONAL", + "Type": "String" + }, + "MyDomainCert": { + "Default": "another-api-arn", "Type": "String" }, "MyMTLSUriHTTP": { @@ -24,315 +24,315 @@ "Default": "another-api-v2-truststore-version", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV29c93aac102": { + "Condition": "C1", "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": { + "Fn::Sub": "example-us-gov-west-1.com" + }, + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "another-api-arn", + "EndpointType": "REGIONAL", + "SecurityPolicy": "TLS_1_2" } - ] - }, - "Condition": "C1" - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", + ], + "MutualTlsAuthentication": { + "TruststoreUri": "another-api-v2-truststore-uri", + "TruststoreVersion": "another-api-v2-truststore-version" + }, "Tags": { "httpapi:createdBy": "SAM" } - }, - "Condition": "C1" - }, - "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/implicit": { + "/get": { "Fn::If": [ - "C1", + "C1", { - "post": { + "put": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", + }, + "servers": [ + { + "x-amazon-apigateway-endpoint-configuration": { + "disableExecuteApiEndpoint": false + } + } + ], "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApifetchApiMapping": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "fetch", + "DomainName": { + "Ref": "ApiGatewayDomainNameV29c93aac102" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApigetApiMapping": { + "Condition": "C1", + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "ApiMappingKey": "get", + "DomainName": { + "Ref": "ApiGatewayDomainNameV29c93aac102" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { + "Condition": "C1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermission": { + "Condition": "C1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionImplicitGetPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "C1", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/implicit", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "C1" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "C1", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "C1" - }, - "ApiGatewayDomainNameV29c93aac102": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": { - "Fn::Sub": "example-us-gov-west-1.com" - }, - "DomainNameConfigurations": [ - { - "CertificateArn": "another-api-arn", - "EndpointType": "REGIONAL", - "SecurityPolicy": "TLS_1_2" - } - ], - "MutualTlsAuthentication": { - "TruststoreUri": "another-api-v2-truststore-uri", - "TruststoreVersion": "another-api-v2-truststore-version" - }, - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "C1" - }, - "MyFunctionApiPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "C1" - }, - "MyApigetApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV29c93aac102" - }, - "ApiMappingKey": "get", - "Stage": { - "Ref": "MyApiProdStage" - } - }, - "Condition": "C1" - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "C1" - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessHttpApi": { + "Condition": "C1", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get": { + "/implicit": { "Fn::If": [ - "C1", + "C1", { - "put": { + "post": { "Fn::If": [ - "C1", + "C1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "C1", + "C1", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ], - "servers": [ - { - "x-amazon-apigateway-endpoint-configuration": { - "disableExecuteApiEndpoint": false - } - } ] } - }, - "Condition": "C1" - }, - "MyApifetchApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Condition": "C1", "Properties": { "ApiId": { - "Ref": "MyApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV29c93aac102" - }, - "ApiMappingKey": "fetch", - "Stage": { - "Ref": "MyApiProdStage" + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - }, - "Condition": "C1" + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_binary_media_types.json b/tests/translator/output/aws-us-gov/api_with_binary_media_types.json index 3e2dc7c199..8a730f0db3 100644 --- a/tests/translator/output/aws-us-gov/api_with_binary_media_types.json +++ b/tests/translator/output/aws-us-gov/api_with_binary_media_types.json @@ -1,219 +1,219 @@ { "Parameters": { "BMT": { - "Default": "image~1jpg", + "Default": "image~1jpg", "Type": "String" } - }, + }, "Resources": { + "ExplicitApi": { + "Properties": { + "BinaryMediaTypes": [ + "image~1gif", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "application~1octet-stream", + "image~1jpg" + ], + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { "Properties": { "BinaryMediaTypes": [ - "image~1gif", + "image~1gif", { "Fn::Join": [ - "~1", + "~1", [ - "image", + "image", "png" ] ] - }, - "application~1octet-stream", - "image~1jpg" - ], - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment9746c8328e" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment9746c8328e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 9746c8328eca81d7b29fed89d9203021b42242ec", - "StageName": "Stage" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { + } + ], "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/gif", + "image/gif", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] } ] - }, - "BinaryMediaTypes": [ - "image~1gif", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - } - ], + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment9746c8328e": { + "Properties": { + "Description": "RestApi deployment id: 9746c8328eca81d7b29fed89d9203021b42242ec", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment9746c8328e" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_binary_media_types_definition_body.json b/tests/translator/output/aws-us-gov/api_with_binary_media_types_definition_body.json index 75b031c547..76b75f995b 100644 --- a/tests/translator/output/aws-us-gov/api_with_binary_media_types_definition_body.json +++ b/tests/translator/output/aws-us-gov/api_with_binary_media_types_definition_body.json @@ -1,150 +1,150 @@ { "Parameters": { "BMT": { - "Default": "image~1jpeg", + "Default": "image~1jpeg", "Type": "String" } - }, + }, "Resources": { - "ExplicitApiManagedSwaggerProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2" - }, - "RestApiId": { - "Ref": "ExplicitApiManagedSwagger" - }, - "StageName": "Prod" - } - }, - "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApiManagedSwagger" - }, - "Description": "RestApi deployment id: fe9c2c09a27ce00c2fa53d5a491cf343e6a3278e", - "StageName": "Stage" - } - }, "ExplicitApiDefinitionBody": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "BinaryMediaTypes": [ + "image~1jpeg", + "image~1jpg", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "application~1json" + ], "Body": { - "paths": {}, - "swagger": "2.0", + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/jpeg", - "image/jpg", + "image/jpeg", + "image/jpg", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] - }, + }, "application/json" ] - }, - "BinaryMediaTypes": [ - "image~1jpeg", - "image~1jpg", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - }, - "application~1json" - ], + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ExplicitApiDefinitionBodyDeployment1f26996adb": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 1f26996adbe5077359ecb2bb0688a9cc0ae8e4fc", "RestApiId": { "Ref": "ExplicitApiDefinitionBody" - }, - "Description": "RestApi deployment id: 1f26996adbe5077359ecb2bb0688a9cc0ae8e4fc", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiDefinitionBodyProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDefinitionBodyDeployment1f26996adb" - }, + }, "RestApiId": { "Ref": "ExplicitApiDefinitionBody" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, "ExplicitApiManagedSwagger": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { + "BinaryMediaTypes": [ + "image~1jpeg", + "image~1jpg", + { + "Fn::Join": [ + "~1", + [ + "image", + "png" + ] + ] + }, + "image~1gif" + ], "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0", + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-binary-media-types": [ - "image/jpeg", - "image/jpg", + "image/jpeg", + "image/jpg", { "Fn::Join": [ - "/", + "/", [ - "image", + "image", "png" ] ] - }, + }, "image/gif" ] - }, - "BinaryMediaTypes": [ - "image~1jpeg", - "image~1jpg", - { - "Fn::Join": [ - "~1", - [ - "image", - "png" - ] - ] - }, - "image~1gif" - ], + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2": { + "Properties": { + "Description": "RestApi deployment id: fe9c2c09a27ce00c2fa53d5a491cf343e6a3278e", + "RestApiId": { + "Ref": "ExplicitApiManagedSwagger" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiManagedSwaggerProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiManagedSwaggerDeploymentfe9c2c09a2" + }, + "RestApiId": { + "Ref": "ExplicitApiManagedSwagger" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_canary_setting.json b/tests/translator/output/aws-us-gov/api_with_canary_setting.json index d33fda88e3..7533c3bc4a 100644 --- a/tests/translator/output/aws-us-gov/api_with_canary_setting.json +++ b/tests/translator/output/aws-us-gov/api_with_canary_setting.json @@ -1,7 +1,53 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "CanarySetting": { + "PercentTraffic": 100, + "StageVariablesOverrides": { + "sv1": "test", + "sv2": "test2" + }, + "UseStageCache": false + }, + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,161 +63,84 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "CanarySetting": { - "PercentTraffic": 100, - "UseStageCache": false, - "StageVariablesOverrides": { - "sv2": "test2", - "sv1": "test" - } - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment5b2cb4ba8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "CanarySetting": { - "PercentTraffic": 100, - "UseStageCache": false, - "StageVariablesOverrides": { - "sv2": "test2", - "sv1": "test" + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -185,7 +154,38 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5b2cb4ba8f": { + "Properties": { + "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CanarySetting": { + "PercentTraffic": 100, + "StageVariablesOverrides": { + "sv1": "test", + "sv2": "test2" + }, + "UseStageCache": false + }, + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_cors.json b/tests/translator/output/aws-us-gov/api_with_cors.json index 369d19951b..a6a47e7ccb 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors.json +++ b/tests/translator/output/aws-us-gov/api_with_cors.json @@ -1,537 +1,537 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionAnyApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ServerlessRestApiDeployment1754a26207": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 1754a26207ccaa4f36c763f1f3993638ba8e8d0a", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment3a5a78688c": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment1754a26207" - }, + "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment3a5a78688c" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment3a5a78688c": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 3a5a78688c9bc377d53aa4153a11f0c4f6e7364c", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { - "/foo": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } + }, "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + } + }, + "/foo": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } } - }, - "responses": {} - } - }, - "/": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "consumes": [ - "application/json" - ], - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - }, - "description": "Default response for CORS method" - } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment1754a26207": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: 1754a26207ccaa4f36c763f1f3993638ba8e8d0a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment1754a26207" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_auth_no_preflight_auth.json b/tests/translator/output/aws-us-gov/api_with_cors_and_auth_no_preflight_auth.json index 9492ea1460..516f1a2190 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_auth_no_preflight_auth.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_auth_no_preflight_auth.json @@ -1,310 +1,297 @@ { "Resources": { + "ApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, + "get": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ], - "responses": {} - }, - "options": { + ], "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - } - } + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" } - }, + } + }, + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + "in": "header", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "identitySource": "method.request.header.Authorization1", "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] } } ] - } - }, + }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, "x-amazon-apigateway-authtype": "custom" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessApiDeployment0aae939ae6": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 0aae939ae622ada18aa063187fce7bef5605e7a6", "RestApiId": { "Ref": "ServerlessApi" - }, - "Description": "RestApi deployment id: 0aae939ae622ada18aa063187fce7bef5605e7a6", + }, "StageName": "Stage" - } - }, - "ServerlessApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessApiDeployment0aae939ae6" - }, - "RestApiId": { - "Ref": "ServerlessApi" - }, - "StageName": "Prod" - } - }, - "ApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessApi" - } - } - ] - } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessApi" - } - } - ] - } - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ServerlessApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Fn::GetAtt": [ - "MyAuthFn", + "MyAuthFn", "Arn" ] - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", { "__ApiId__": { "Ref": "ServerlessApi" @@ -312,7 +299,20 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessApiDeployment0aae939ae6" + }, + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_auth_preflight_auth.json b/tests/translator/output/aws-us-gov/api_with_cors_and_auth_preflight_auth.json index 409391c8a8..7f96daf9a9 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_auth_preflight_auth.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_auth_preflight_auth.json @@ -1,7 +1,6 @@ { "Resources": { "ApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessApi" @@ -93,10 +62,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +74,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "ServerlessApi" @@ -114,10 +83,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyAuthFn": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -137,13 +136,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyAuthFnRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -156,7 +154,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -167,85 +166,50 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] - }, - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" } - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "type": "string" }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "type": "string" } } @@ -255,80 +219,112 @@ { "MyLambdaRequestAuth": [] } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] - }, + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + }, + "/any": { "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "security": [ { "MyLambdaRequestAuth": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -342,45 +338,36 @@ } ] }, - "identitySource": "method.request.header.Authorization1" - } + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessApiDeploymentc2a3913910": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: c2a3913910ac757cced600f36f4fef45b2e4bfa8", "RestApiId": { "Ref": "ServerlessApi" }, "StageName": "Stage" - } - }, - "ServerlessApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessApiDeploymentc2a3913910" - }, - "RestApiId": { - "Ref": "ServerlessApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -400,7 +387,20 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessApiDeploymentc2a3913910" + }, + "RestApiId": { + "Ref": "ServerlessApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_conditions_no_definitionbody.json b/tests/translator/output/aws-us-gov/api_with_cors_and_conditions_no_definitionbody.json index 79de7572ec..ad96f411f4 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_conditions_no_definitionbody.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_conditions_no_definitionbody.json @@ -9,8 +9,234 @@ } }, "Resources": { - "ImplicitApiFunction2": { - "Type": "AWS::Lambda::Function", + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "delete": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction2.Arn}/invocations" + } + } + }, + "get": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'www.example.com'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "/any": { + "Fn::If": [ + "MyCondition", + { + "options": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'www.example.com'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "Fn::If": [ + "MyCondition", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "MyCondition", + { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentc78ebf0832": { + "Properties": { + "Description": "RestApi deployment id: c78ebf083257039f9ac5b13d52c7ff7ae8ba90e7", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentc78ebf0832" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Condition": "MyCondition", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,7 +245,7 @@ "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunction2Role", + "ImplicitApiFunctionRole", "Arn" ] }, @@ -30,40 +256,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunction2Role": { - "Type": "AWS::IAM::Role", + "ImplicitApiFunction2": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunction2Role", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunction2DeleteHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -81,38 +300,12 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Condition": "MyCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Condition": "MyCondition", + "ImplicitApiFunction2Role": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -125,7 +318,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -136,10 +330,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -149,7 +343,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ExplicitApi" @@ -158,10 +352,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -171,7 +365,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ExplicitApi" @@ -180,10 +374,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionPostHtmlPermissionProd": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", @@ -193,7 +387,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "ExplicitApi" @@ -202,233 +396,39 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { + "Condition": "MyCondition", "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "delete": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction2.Arn}/invocations" - } - }, - "responses": {} - }, - "get": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "post": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] - }, - "options": { - "summary": "CORS support", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'www.example.com'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,OPTIONS,POST'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - } - } - } } - }, - "/any": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-any-method": { - "Fn::If": [ - "MyCondition", - { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::If": [ - "MyCondition", - { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "options": { - "summary": "CORS support", - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'www.example.com'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, - "Access-Control-Allow-Methods": { - "type": "string" - } - } - } - } - } - }, - { - "Ref": "AWS::NoValue" - } - ] } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeploymentc78ebf0832": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: c78ebf083257039f9ac5b13d52c7ff7ae8ba90e7", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentc78ebf0832" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json index 13650f8456..cce402b565 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_credentials_false.json @@ -1,207 +1,207 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment398246867a" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment398246867a": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment398246867a": { + "Properties": { + "Description": "RestApi deployment id: 398246867a6d5535e40b46e224e8998486a4b9eb", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment398246867a" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_headers.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_headers.json index cbdf27d25b..bc236b2839 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_headers.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_headers.json @@ -1,369 +1,369 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiDeployment8e16bddf6b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 8e16bddf6b1212fc4a42840a3a6722842de272ca", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment03e65d7ea2" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment8e16bddf6b" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ExplicitApiDeployment03e65d7ea2": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 03e65d7ea2275d648803eecb7fa8e0ae7cd8f0aa", "RestApiId": { "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 03e65d7ea2275d648803eecb7fa8e0ae7cd8f0aa", + }, "StageName": "Stage" - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment03e65d7ea2" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", - "method.response.header.Access-Control-Allow-Headers": "headers" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment8e16bddf6b": { + "Properties": { + "Description": "RestApi deployment id: 8e16bddf6b1212fc4a42840a3a6722842de272ca", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment8e16bddf6b" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json index bd02c3bea6..0b8ff7e329 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_maxage.json @@ -1,215 +1,215 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymentb61cfb7d60": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: b61cfb7d602d889bbd9867dcbf0f75d3066dcc56", - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentb61cfb7d60" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Max-Age": 600, - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, + "Access-Control-Allow-Origin": { + "type": "string" + }, "Access-Control-Max-Age": { "type": "integer" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Max-Age": 600 + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Max-Age": 600, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" - }, + }, + "Access-Control-Allow-Origin": { + "type": "string" + }, "Access-Control-Max-Age": { "type": "integer" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Max-Age": 600 + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentb61cfb7d60": { + "Properties": { + "Description": "RestApi deployment id: b61cfb7d602d889bbd9867dcbf0f75d3066dcc56", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentb61cfb7d60" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_methods.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_methods.json index e85d393d61..8f46afe6bb 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_methods.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_methods.json @@ -1,7 +1,6 @@ { "Resources": { "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,148 +62,178 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "methods" + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "'*'" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } } }, "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "'*'", - "method.response.header.Access-Control-Allow-Methods": "methods" + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "'*'" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment82f9bf33a1": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 82f9bf33a18bf398cbc6b03f415b9f6c2280c982", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment82f9bf33a1" @@ -243,7 +242,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_cors_and_only_origins.json b/tests/translator/output/aws-us-gov/api_with_cors_and_only_origins.json index 8ab271326d..58798750e1 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_and_only_origins.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_and_only_origins.json @@ -1,357 +1,357 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeploymenta7a992bbb6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a7a992bbb604dcd7667af3caa050bf14af2bf684", - "StageName": "Stage" - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymenta7a992bbb6" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentc934a493f3" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta7a992bbb6": { + "Properties": { + "Description": "RestApi deployment id: a7a992bbb604dcd7667af3caa050bf14af2bf684", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymenta7a992bbb6" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ServerlessRestApiDeploymentc934a493f3": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionPostHtmlPermissionProd": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: c934a493f3473efce5bb2acbf1d54e9c2ce0fef3", - "StageName": "Stage" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { - "post": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { - "type": "string" - }, "Access-Control-Allow-Methods": { "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, - "get": { + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentc934a493f3": { + "Properties": { + "Description": "RestApi deployment id: c934a493f3473efce5bb2acbf1d54e9c2ce0fef3", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentc934a493f3" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_cors_no_definitionbody.json b/tests/translator/output/aws-us-gov/api_with_cors_no_definitionbody.json index cd0a40e3ca..307b98fced 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_no_definitionbody.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_no_definitionbody.json @@ -1,272 +1,155 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "ImplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", - { - "__ApiId__": { - "Ref": "ExplicitApi" - }, - "__Stage__": "*" - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, - "post": { - "x-amazon-apigateway-integration": { "type": "aws_proxy", - "httpMethod": "POST", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS,POST'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + }, + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} - }, + } + } + }, + "/any": { "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "origins" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeployment9080d99115": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 9080d99115784303ab348562cca88235c3a131aa", "RestApiId": { "Ref": "ExplicitApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment9080d99115" @@ -275,7 +158,124 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionPostHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_cors_openapi_3.json b/tests/translator/output/aws-us-gov/api_with_cors_openapi_3.json index a4451857f2..b45137f117 100644 --- a/tests/translator/output/aws-us-gov/api_with_cors_openapi_3.json +++ b/tests/translator/output/aws-us-gov/api_with_cors_openapi_3.json @@ -1,531 +1,531 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ImplicitApiFunctionAnyApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ImplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "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": {} - }, "options": { - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } - } - } - }, "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - } - }, - "/{proxy+}": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, "responseTemplates": { "application/json": "{}\n" - }, - "responseParameters": { - "method.response.header.Access-Control-Allow-Headers": "headers", - "method.response.header.Access-Control-Allow-Origin": "origins", - "method.response.header.Access-Control-Allow-Methods": "methods", - "method.response.header.Access-Control-Allow-Credentials": "'true'" - } + }, + "statusCode": "200" } + }, + "type": "mock" + } + }, + "post": { + "responses": {}, + "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" } - }, + } + } + }, + "/{proxy+}": { + "options": { "consumes": [ "application/json" - ], - "summary": "CORS support", + ], + "produces": [ + "application/json" + ], "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Credentials": { "type": "string" - }, + }, "Access-Control-Allow-Headers": { "type": "string" - }, + }, "Access-Control-Allow-Methods": { "type": "string" - }, - "Access-Control-Allow-Credentials": { + }, + "Access-Control-Allow-Origin": { "type": "string" } - }, - "description": "Default response for CORS method" + } } - }, - "produces": [ - "application/json" - ] - }, + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Credentials": "'true'", + "method.response.header.Access-Control-Allow-Headers": "headers", + "method.response.header.Access-Control-Allow-Methods": "methods", + "method.response.header.Access-Control-Allow-Origin": "origins" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment8cc53ffaa5": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment8493e7adfe" - }, + "Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment8cc53ffaa5" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionAnyApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/foo", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment8cc53ffaa5": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 8cc53ffaa59a19b69e73d5b422142c7396739b16" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment8493e7adfe": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 8493e7adfe1ae5a1112328c0633eea5cdce0633c" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { - "/foo": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } + }, "options": { + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "schema": { + "type": "string" + } + }, + "Access-Control-Allow-Origin": { + "schema": { + "type": "string" + } + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" - } + } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" } - } - }, - "summary": "CORS support", + }, + "type": "mock" + } + } + }, + "/foo": { + "options": { "responses": { "200": { + "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } - }, - "Access-Control-Allow-Methods": { + }, + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } - }, - "description": "Default response for CORS method" - } - } - }, - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } } - }, - "responses": {} - } - }, - "/": { - "options": { + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" - }, + }, "responses": { "default": { - "statusCode": "200", - "responseTemplates": { - "application/json": "{}\n" - }, "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", "method.response.header.Access-Control-Allow-Origin": { "Fn::Join": [ - ",", + ",", [ - "www.amazon.com", + "www.amazon.com", "www.google.com" ] ] - }, - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - } - } - } - }, - "summary": "CORS support", - "responses": { - "200": { - "headers": { - "Access-Control-Allow-Origin": { - "schema": { - "type": "string" } - }, - "Access-Control-Allow-Methods": { - "schema": { - "type": "string" - } - } - }, - "description": "Default response for CORS method" - } + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" } - }, - "get": { + }, + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0" - }, + } + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment8493e7adfe": { "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Description": "RestApi deployment id: 8493e7adfe1ae5a1112328c0633eea5cdce0633c", + "RestApiId": { + "Ref": "ServerlessRestApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment8493e7adfe" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json index 362045c0b4..6e16f44e90 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53.json @@ -10,94 +10,76 @@ } }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainName0caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" + "CertificateArn": "cert-arn-in-us-east-1", + "DomainName": "example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + } + }, + "Type": "AWS::ApiGateway::DomainName" }, - "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApi": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } } } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiDeployment1deeaff693": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 1deeaff6933b892391de7a35e4cf92e79a47aea9", "RestApiId": { "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 1deeaff6933b892391de7a35e4cf92e79a47aea9" - } + } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", + "MyApiProdStage": { "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, - { - "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", - "DistributionDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" - } - ] - } + "DeploymentId": { + "Ref": "MyApiDeployment1deeaff693" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "BasePath": "one", "DomainName": { @@ -109,25 +91,55 @@ "Stage": { "Ref": "MyApiProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunction": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment1deeaff693" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" }, - "RestApiId": { - "Ref": "MyApi" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -140,66 +152,54 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "DomainName": "example.com" - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "RecordSetGroupbd00d962a4": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } - } + "HostedZoneId": "ZQ1UAL4EFZVME", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "A" }, - "openapi": "3.0.1" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName0caaf24ab1", + "DistributionDomainName" + ] + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json index 5445e4f69e..b5ed499103 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name.json @@ -1,205 +1,205 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { + "ApiGatewayDomainName0caaf24ab1": { + "Properties": { + "CertificateArn": "cert-arn-in-us-east-1", + "DomainName": "example.com", + "EndpointConfiguration": { + "Types": [ + "EDGE" + ] + } + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment501f2306c4": { + "Properties": { + "Description": "RestApi deployment id: 501f2306c4860ed198c3020aa43d453cdbdd6b7a", + "RestApiId": { + "Ref": "MyApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment501f2306c4" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApioneBasePathMapping": { + "Properties": { + "BasePath": "one", + "DomainName": { + "Ref": "ApiGatewayDomainName0caaf24ab1" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "Stage": { + "Ref": "MyApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "MyApiDeployment501f2306c4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 501f2306c4860ed198c3020aa43d453cdbdd6b7a" - } - }, - "MyApioneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "BasePath": "one", - "DomainName": { - "Ref": "ApiGatewayDomainName0caaf24ab1" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "Stage": { - "Ref": "MyApiProdStage" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment501f2306c4" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ApiGatewayDomainName0caaf24ab1": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointConfiguration": { - "Types": [ - "EDGE" - ] - }, - "DomainName": "example.com" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", "Properties": { - "HostedZoneName": "www.my-domain.com.", + "HostedZoneName": "www.my-domain.com.", "RecordSets": [ { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] - } - }, - "Type": "A", - "Name": "example.com" - }, + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "A" + }, { "AliasTarget": { - "HostedZoneId": "Z2FDTNDATAQYW2", "DNSName": { "Fn::GetAtt": [ - "ApiGatewayDomainName0caaf24ab1", + "ApiGatewayDomainName0caaf24ab1", "DistributionDomainName" ] - } - }, - "Type": "AAAA", - "Name": "example.com" + }, + "HostedZoneId": "Z2FDTNDATAQYW2" + }, + "Name": "example.com", + "Type": "AAAA" } ] - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "openapi": "3.0.1" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name_http.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name_http.json index f952f03ad8..2e47f2e153 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name_http.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_hosted_zone_name_http.json @@ -1,191 +1,191 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV20caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": "example.com", + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointType": "REGIONAL" } - ] - } - }, + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", + }, + "AutoDeploy": true, + "StageName": "Prod", "Tags": { "httpapi:createdBy": "SAM" } - } - }, + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "MyApioneApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", "Properties": { "ApiId": { "Ref": "MyApi" - }, + }, + "ApiMappingKey": "one", "DomainName": { "Ref": "ApiGatewayDomainNameV20caaf24ab1" - }, - "ApiMappingKey": "one", + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "ApiGatewayDomainNameV20caaf24ab1": { - "Type": "AWS::ApiGatewayV2::DomainName", + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { "Properties": { - "DomainName": "example.com", - "DomainNameConfigurations": [ + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointType": "REGIONAL" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "RecordSetGroup456ebaf280": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneName": "www.my-domain.com.", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFetchPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroup456ebaf280": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "HostedZoneName": "www.my-domain.com.", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + }, + "Name": "example.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_http.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_http.json index c92bc22424..412f0587a1 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_http.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_http.json @@ -1,209 +1,209 @@ { "Parameters": { "ACMCertificateArn": { - "Default": "cert-arn-in-us-east-1", + "Default": "cert-arn-in-us-east-1", "Type": "String" - }, + }, "DomainName": { - "Default": "example.com", + "Default": "example.com", "Type": "String" } - }, + }, "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayDomainNameV20caaf24ab1": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ + "DomainName": "example.com", + "DomainNameConfigurations": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "CertificateArn": "cert-arn-in-us-east-1", + "EndpointType": "REGIONAL" } - ] - } - }, + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/fetch": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "Prod", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "MyApioneApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", "Properties": { "ApiId": { "Ref": "MyApi" - }, + }, + "ApiMappingKey": "one", "DomainName": { "Ref": "ApiGatewayDomainNameV20caaf24ab1" - }, - "ApiMappingKey": "one", + }, "Stage": { "Ref": "MyApiProdStage" } - } - }, - "RecordSetGroupbd00d962a4": { - "Type": "AWS::Route53::RecordSetGroup", + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyFunction": { "Properties": { - "HostedZoneId": "ZQ1UAL4EFZVME", - "RecordSets": [ - { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "A", - "Name": "example.com" - }, + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV20caaf24ab1", - "RegionalDomainName" - ] - } - }, - "Type": "AAAA", - "Name": "example.com" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ApiGatewayDomainNameV20caaf24ab1": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "example.com", - "DomainNameConfigurations": [ - { - "CertificateArn": "cert-arn-in-us-east-1", - "EndpointType": "REGIONAL" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionFetchPermission": { "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFetchPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "RecordSetGroupbd00d962a4": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" + "HostedZoneId": "ZQ1UAL4EFZVME", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - ] - } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/fetch": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + }, + "Name": "example.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV20caaf24ab1", + "RegionalHostedZoneId" + ] } - } - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + }, + "Name": "example.com", + "Type": "AAAA" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple.json index 22f7744482..5e64d4738f 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple.json @@ -2,28 +2,31 @@ "AWSTemplateFormatVersion": "2010-09-09", "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", "Resources": { - "ApiGatewayAdminTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminOne": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminTwoDeployment61887a4eed" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminOneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName5fe29fe649" @@ -34,108 +37,132 @@ "Stage": { "Ref": "ApiGatewayAdminOneProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ApiGatewayAdminOneDeploymentdd3f545183": { + "Properties": { + "Description": "RestApi deployment id: dd3f545183668c401e771fd9a377cfeadcf88a35", + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayAdminOneProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayAdminOneDeploymentdd3f545183" }, - "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Prod", - "TracingEnabled": true, "MethodSettings": [ { "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } - }, - "ApiGatewayAdminThreeDeployment7541e97159": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7541e971598cffe7cafab030d3fccc687d508f59", - "RestApiId": { - "Ref": "ApiGatewayAdminThree" - }, - "StageName": "Stage" - } - }, - "ApiGatewayAdminOneDeploymentdd3f545183": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: dd3f545183668c401e771fd9a377cfeadcf88a35", + ], "RestApiId": { "Ref": "ApiGatewayAdminOne" }, - "StageName": "Stage" - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminThree": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminTwoDeployment61887a4eed": { - "Type": "AWS::ApiGateway::Deployment", + "ApiGatewayAdminThreeBasePathMapping": { "Properties": { - "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "DomainName": { + "Ref": "ApiGatewayDomainName41bfc7f9c4" + }, "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminThree" + }, + "Stage": { + "Ref": "ApiGatewayAdminThreeProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "ApiGatewayAdminThreeDeployment7541e97159": { + "Properties": { + "Description": "RestApi deployment id: 7541e971598cffe7cafab030d3fccc687d508f59", + "RestApiId": { + "Ref": "ApiGatewayAdminThree" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiGatewayAdminThree": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayAdminThreeDeployment7541e97159" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminThree" + }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayAdminTwo": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, "swagger": "2.0" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ApiGatewayDomainName5fe29fe649": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.one.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminTwoBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName3fd2dbd8f8" @@ -146,163 +173,136 @@ "Stage": { "Ref": "ApiGatewayAdminTwoProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayAdminTwo": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminTwoDeployment61887a4eed": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" + "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiGatewayAdminTwoProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayAdminTwoDeployment61887a4eed" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, "ApiGatewayDomainName41bfc7f9c4": { - "Type": "AWS::ApiGateway::DomainName", "Properties": { - "RegionalCertificateArn": "arn::cert::abc", "DomainName": "admin.three.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } - }, - "ApiGatewayAdminThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminThreeDeployment7541e97159" }, - "RestApiId": { - "Ref": "ApiGatewayAdminThree" - }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminThreeBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayDomainName5fe29fe649": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName41bfc7f9c4" - }, - "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "DomainName": "admin.one.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "Stage": { - "Ref": "ApiGatewayAdminThreeProdStage" - } - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", "Properties": { "HostedZoneId": "abc123456", "RecordSets": [ { - "Name": "admin.two.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.two.amazon.com", + "Type": "A" }, { - "Name": "admin.three.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName41bfc7f9c4", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName41bfc7f9c4", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.three.amazon.com", + "Type": "A" }, { - "Name": "admin.one.amazon.com", - "Type": "A", "AliasTarget": { - "HostedZoneId": { + "DNSName": { "Fn::GetAtt": [ "ApiGatewayDomainName5fe29fe649", - "RegionalHostedZoneId" + "RegionalDomainName" ] }, - "DNSName": { + "HostedZoneId": { "Fn::GetAtt": [ "ApiGatewayDomainName5fe29fe649", - "RegionalDomainName" + "RegionalHostedZoneId" ] } - } + }, + "Name": "admin.one.amazon.com", + "Type": "A" } ] - } - }, - "ApiGatewayAdminOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json index 26b978e901..087c720574 100644 --- a/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json +++ b/tests/translator/output/aws-us-gov/api_with_custom_domain_route53_multiple_intrinsic_hostedzoneid.json @@ -7,100 +7,99 @@ } }, "Resources": { - "RecordSetGroupd9cb5a3e02": { - "Type": "AWS::Route53::RecordSetGroup", + "ApiGatewayAdminOne": { "Properties": { - "HostedZoneId": { - "Fn::Sub": "{{MyHostedZoneId}}" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "RecordSets": [ - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" - ] - } - } - } - ] - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminOneBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminTwoDeploymentca2a75b5dd" + "DomainName": { + "Ref": "ApiGatewayDomainName5fe29fe649" }, "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminOne" }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Stage": { + "Ref": "ApiGatewayAdminOneProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayDomainName5fe29fe649": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminOneDeployment066bb1ceae": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.one.amazon.com", - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "Description": "RestApi deployment id: 066bb1ceaebd0cafae99258bbe7130af8b676372", + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayAdminOneProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayAdminOneDeployment066bb1ceae" }, - "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Prod", - "TracingEnabled": true, "MethodSettings": [ { "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminOne" + }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", + "ApiGatewayAdminThree": { "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ApiGatewayAdminThreeBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", "Properties": { "DomainName": { "Ref": "ApiGatewayDomainName41bfc7f9c4" @@ -111,215 +110,216 @@ "Stage": { "Ref": "ApiGatewayAdminThreeProdStage" } - } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, - "ApiGatewayAdminOneBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", + "ApiGatewayAdminThreeDeployment169349c1e9": { "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName5fe29fe649" - }, + "Description": "RestApi deployment id: 169349c1e96a0f130ee35f7bb9d83b042c386d6f", "RestApiId": { - "Ref": "ApiGatewayAdminOne" + "Ref": "ApiGatewayAdminThree" }, - "Stage": { - "Ref": "ApiGatewayAdminOneProdStage" - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "RecordSetGroupd28e0e19d0": { - "Type": "AWS::Route53::RecordSetGroup", + "ApiGatewayAdminThreeProdStage": { "Properties": { - "HostedZoneId": { - "Ref": "MyHostedZoneId" + "DeploymentId": { + "Ref": "ApiGatewayAdminThreeDeployment169349c1e9" }, - "RecordSets": [ - { - "Name": "admin.three.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName41bfc7f9c4", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName41bfc7f9c4", - "RegionalDomainName" - ] - } - } - }, + "MethodSettings": [ { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName5fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName5fe29fe649", - "RegionalDomainName" - ] - } - } + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" } - ] - } - }, - "ApiGatewayAdminOneDeployment066bb1ceae": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 066bb1ceaebd0cafae99258bbe7130af8b676372", + ], "RestApiId": { - "Ref": "ApiGatewayAdminOne" - }, - "StageName": "Stage" - } - }, - "ApiGatewayAdminTwoBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName3fd2dbd8f8" - }, - "RestApiId": { - "Ref": "ApiGatewayAdminTwo" + "Ref": "ApiGatewayAdminThree" }, - "Stage": { - "Ref": "ApiGatewayAdminTwoProdStage" - } - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" }, "ApiGatewayAdminTwo": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, "swagger": "2.0" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ApiGatewayDomainName41bfc7f9c4": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.three.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiGatewayAdminThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiGatewayAdminTwoBasePathMapping": { "Properties": { - "DeploymentId": { - "Ref": "ApiGatewayAdminThreeDeployment169349c1e9" + "DomainName": { + "Ref": "ApiGatewayDomainName3fd2dbd8f8" }, "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "Ref": "ApiGatewayAdminTwo" }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "Stage": { + "Ref": "ApiGatewayAdminTwoProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" }, "ApiGatewayAdminTwoDeploymentca2a75b5dd": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: ca2a75b5dd3713c71543e80f2b6f5aac9538ea9c", "RestApiId": { "Ref": "ApiGatewayAdminTwo" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "ApiGatewayAdminThree": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayAdminTwoProdStage": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" + "DeploymentId": { + "Ref": "ApiGatewayAdminTwoDeploymentca2a75b5dd" }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayAdminTwo" }, + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminThreeDeployment169349c1e9": { - "Type": "AWS::ApiGateway::Deployment", + "ApiGatewayDomainName41bfc7f9c4": { "Properties": { - "Description": "RestApi deployment id: 169349c1e96a0f130ee35f7bb9d83b042c386d6f", - "RestApiId": { - "Ref": "ApiGatewayAdminThree" + "DomainName": "admin.three.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "StageName": "Stage" - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" }, - "ApiGatewayAdminOne": { - "Type": "AWS::ApiGateway::RestApi", + "ApiGatewayDomainName5fe29fe649": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, + "DomainName": "admin.one.amazon.com", "EndpointConfiguration": { "Types": [ "REGIONAL" ] - } - } + }, + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "RecordSetGroupd28e0e19d0": { + "Properties": { + "HostedZoneId": { + "Ref": "MyHostedZoneId" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName41bfc7f9c4", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName41bfc7f9c4", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.three.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName5fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName5fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" + }, + "RecordSetGroupd9cb5a3e02": { + "Properties": { + "HostedZoneId": { + "Fn::Sub": "{{MyHostedZoneId}}" + }, + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth.json b/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth.json index 9d43ce2aee..613c2c988b 100644 --- a/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth.json +++ b/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth.json @@ -1,163 +1,43 @@ { "Resources": { - "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionWithAwsIamAuthRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyApiWithAwsIamAuthDeploymentf9a4964a7d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "Description": "RestApi deployment id: f9a4964a7df5021874e5a094662f1a2443982e0a", - "StageName": "Stage" - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithAwsIamAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuth" - } - } - ] - } - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeploymentf9a4964a7d" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } - }, - "MyApiWithAwsIamAuthAndDefaultInvokeRoleProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentce2dead7de" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - }, - "StageName": "Prod" - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionWithAwsIamAuth" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - } - } - ] - } - } - }, - "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentce2dead7de": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" - }, - "Description": "RestApi deployment id: ce2dead7ded0bb502db5bd0c105948c27bc96729", - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthAndCustomInvokeRoleDeploymentb31aa75bb2": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - }, - "Description": "RestApi deployment id: b31aa75bb2284229d40917a9b424c8ea1cf98217", - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthAndCustomInvokeRole": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithAwsIamAuth": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "post": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -167,59 +47,47 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyApiWithAwsIamAuthAndCustomInvokeRoleProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRoleDeploymentb31aa75bb2" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithAwsIamAuthAndDefaultInvokeRole": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithAwsIamAuthAndCustomInvokeRole": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "put": { + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -229,47 +97,69 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithAwsIamAuthAndCustomInvokeRoleDeploymentb31aa75bb2": { + "Properties": { + "Description": "RestApi deployment id: b31aa75bb2284229d40917a9b424c8ea1cf98217", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthAndCustomInvokeRoleProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRoleDeploymentb31aa75bb2" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRole": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "get": { + "put": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "security": [ - { - "AWS_IAM": [] } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "AWS_IAM": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authtype": "awsSigv4" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -279,43 +169,142 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentce2dead7de": { + "Properties": { + "Description": "RestApi deployment id: ce2dead7ded0bb502db5bd0c105948c27bc96729", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthAndDefaultInvokeRoleProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRoleDeploymentce2dead7de" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithAwsIamAuthDeploymentf9a4964a7d": { + "Properties": { + "Description": "RestApi deployment id: f9a4964a7df5021874e5a094662f1a2443982e0a", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeploymentf9a4964a7d" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionWithAwsIamAuth": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionWithAwsIamAuthRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionWithAwsIamAuth" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiWithAwsIamAuthAndCustomInvokeRole" - } + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithAwsIamAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuthAndDefaultInvokeRole" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionWithAwsIamAuth" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyApiWithAwsIamAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -328,9 +317,20 @@ ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth_and_no_auth_route.json b/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth_and_no_auth_route.json index e56679cdee..3eff2cab0d 100644 --- a/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth_and_no_auth_route.json +++ b/tests/translator/output/aws-us-gov/api_with_default_aws_iam_auth_and_no_auth_route.json @@ -1,7 +1,128 @@ { "Resources": { + "MyApiWithAwsIamAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/iam": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/none": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithAwsIamAuthDeploymentf50d541bef": { + "Properties": { + "Description": "RestApi deployment id: f50d541bef5f3b607af4650464da9c65103e8dc3", + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithAwsIamAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithAwsIamAuthDeploymentf50d541bef" + }, + "RestApiId": { + "Ref": "MyApiWithAwsIamAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +142,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +154,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -72,10 +163,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithNoAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +175,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -93,10 +184,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithNoAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +196,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/iam", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/none", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -114,10 +205,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithNoAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithNoAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +217,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/none", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApiWithAwsIamAuth" @@ -135,129 +226,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithAwsIamAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithAwsIamAuthRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "NONE": [] - } - ] - } - }, - "/any/iam": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - } - }, - "/any/none": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "NONE": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "AWS_IAM": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "awsSigv4" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithAwsIamAuthDeploymentf50d541bef": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: f50d541bef5f3b607af4650464da9c65103e8dc3", - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithAwsIamAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithAwsIamAuthDeploymentf50d541bef" - }, - "RestApiId": { - "Ref": "MyApiWithAwsIamAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_disable_api_execute_endpoint.json b/tests/translator/output/aws-us-gov/api_with_disable_api_execute_endpoint.json index a044be47c0..7b83b5a93a 100644 --- a/tests/translator/output/aws-us-gov/api_with_disable_api_execute_endpoint.json +++ b/tests/translator/output/aws-us-gov/api_with_disable_api_execute_endpoint.json @@ -1,59 +1,51 @@ { "Resources": { - "ApiGatewayApiDeployment88816bd125": { - "Type": "AWS::ApiGateway::Deployment", + "ApiFunction": { "Properties": { - "RestApiId": { - "Ref": "ApiGatewayApi" + "Code": { + "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" }, - "Description": "RestApi deployment id: 88816bd1258061ab1a1138fb2723a76f221c5111", - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiGatewayApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunctionApiEventPermissionprod": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-endpoint-configuration": { - "disableExecuteApiEndpoint": true - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ApiGatewayApi" + }, + "__Stage__": "*" + } ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::Lambda::Permission" }, "ApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -66,64 +58,71 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayApi": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-endpoint-configuration": { + "disableExecuteApiEndpoint": true + } }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiFunctionApiEventPermissionprod": { - "Type": "AWS::Lambda::Permission", + "ApiGatewayApiDeployment88816bd125": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" + "Description": "RestApi deployment id: 88816bd1258061ab1a1138fb2723a76f221c5111", + "RestApiId": { + "Ref": "ApiGatewayApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ApiGatewayApi" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayApiprodStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayApiDeployment88816bd125" @@ -132,7 +131,8 @@ "Ref": "ApiGatewayApi" }, "StageName": "prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_fail_on_warnings.json b/tests/translator/output/aws-us-gov/api_with_fail_on_warnings.json index 2aece6d1b9..70e4462ec8 100644 --- a/tests/translator/output/aws-us-gov/api_with_fail_on_warnings.json +++ b/tests/translator/output/aws-us-gov/api_with_fail_on_warnings.json @@ -1,57 +1,51 @@ { "Resources": { - "ApiGatewayApiDeployment4539d6d48c": { - "Type": "AWS::ApiGateway::Deployment", + "ApiFunction": { "Properties": { - "RestApiId": { - "Ref": "ApiGatewayApi" + "Code": { + "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" }, - "Description": "RestApi deployment id: 4539d6d48c1b3fdc71e492190aa2eeff27526d7f", - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "ApiFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiGatewayApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiFunctionApiEventPermissionprod": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "swagger": "2.0" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiFunction" }, - "FailOnWarnings": true, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ApiGatewayApi" + }, + "__Stage__": "*" + } ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::Lambda::Permission" }, "ApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -64,64 +58,69 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ApiFunction": { - "Type": "AWS::Lambda::Function", + "ApiGatewayApi": { "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "def handler(event, context):\n return {'body': 'Hello World!', 'statusCode': 200}\n" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" }, - "Role": { - "Fn::GetAtt": [ - "ApiFunctionRole", - "Arn" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "Runtime": "python3.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "FailOnWarnings": true, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ApiFunctionApiEventPermissionprod": { - "Type": "AWS::Lambda::Permission", + "ApiGatewayApiDeployment4539d6d48c": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ApiFunction" + "Description": "RestApi deployment id: 4539d6d48c1b3fdc71e492190aa2eeff27526d7f", + "RestApiId": { + "Ref": "ApiGatewayApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ApiGatewayApi" - } - } - ] - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ApiGatewayApiprodStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiGatewayApiDeployment4539d6d48c" @@ -130,7 +129,8 @@ "Ref": "ApiGatewayApi" }, "StageName": "prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_gateway_responses.json b/tests/translator/output/aws-us-gov/api_with_gateway_responses.json index 936b9c68cc..7bfac8335f 100644 --- a/tests/translator/output/aws-us-gov/api_with_gateway_responses.json +++ b/tests/translator/output/aws-us-gov/api_with_gateway_responses.json @@ -1,89 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiDeployment929d2126a7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 929d2126a7a3b228757ccb4aa5e896c1bd5c76e8", - "StageName": "Stage" - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -91,9 +27,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -108,10 +44,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment929d2126a7": { + "Properties": { + "Description": "RestApi deployment id: 929d2126a7a3b228757ccb4aa5e896c1bd5c76e8", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment929d2126a7" @@ -120,28 +66,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_gateway_responses_all.json b/tests/translator/output/aws-us-gov/api_with_gateway_responses_all.json index 599af342cf..d8a0e32b0b 100644 --- a/tests/translator/output/aws-us-gov/api_with_gateway_responses_all.json +++ b/tests/translator/output/aws-us-gov/api_with_gateway_responses_all.json @@ -1,89 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiDeployment42329c77b0": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 42329c77b0faabe3a86487f92af32b9afe0a0fa1", - "StageName": "Stage" - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -98,9 +34,9 @@ }, "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", - "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", + "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", "gatewayresponse.path.PathKey": "'path-value'", "gatewayresponse.querystring.QueryStringKey": "'query-string-value'" }, @@ -117,10 +53,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment42329c77b0": { + "Properties": { + "Description": "RestApi deployment id: 42329c77b0faabe3a86487f92af32b9afe0a0fa1", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment42329c77b0" @@ -129,28 +75,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_gateway_responses_all_openapi_3.json b/tests/translator/output/aws-us-gov/api_with_gateway_responses_all_openapi_3.json index 67623b4745..58affc1dbe 100644 --- a/tests/translator/output/aws-us-gov/api_with_gateway_responses_all_openapi_3.json +++ b/tests/translator/output/aws-us-gov/api_with_gateway_responses_all_openapi_3.json @@ -1,155 +1,155 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0", "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "openapi": "3.0", + }, "x-amazon-apigateway-gateway-responses": { "QUOTA_EXCEEDED": { "responseParameters": { "gatewayresponse.header.Retry-After": "'31536000'" - }, - "responseTemplates": {}, + }, + "responseTemplates": {}, "statusCode": "429" - }, + }, "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", - "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", - "gatewayresponse.path.PathKey": "'path-value'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", + "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.path.PathKey": "'path-value'", "gatewayresponse.querystring.QueryStringKey": "'query-string-value'" - }, - "responseTemplates": {}, + }, + "responseTemplates": {}, "statusCode": "401" } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment0f8408588e": { + "Properties": { + "Description": "RestApi deployment id: 0f8408588e16013e6d4fa0f1fd2390d0a7ec15ed", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment0f8408588e" - }, + }, "RestApiId": { "Ref": "ExplicitApi" - }, + }, "StageName": "Prod" - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApiDeployment0f8408588e": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 0f8408588e16013e6d4fa0f1fd2390d0a7ec15ed" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_gateway_responses_implicit.json b/tests/translator/output/aws-us-gov/api_with_gateway_responses_implicit.json index 8ba952ee43..9ec4515f60 100644 --- a/tests/translator/output/aws-us-gov/api_with_gateway_responses_implicit.json +++ b/tests/translator/output/aws-us-gov/api_with_gateway_responses_implicit.json @@ -1,13 +1,12 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionRole", @@ -17,26 +16,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -49,74 +59,41 @@ ] } } - ] - } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment929d2126a7" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment929d2126a7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 929d2126a7a3b228757ccb4aa5e896c1bd5c76e8", - "StageName": "Stage" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" + ], + "Version": "2012-10-17" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -124,9 +101,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -142,7 +119,30 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment929d2126a7": { + "Properties": { + "Description": "RestApi deployment id: 929d2126a7a3b228757ccb4aa5e896c1bd5c76e8", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment929d2126a7" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_gateway_responses_minimal.json b/tests/translator/output/aws-us-gov/api_with_gateway_responses_minimal.json index ea9059e274..864ef3d6d4 100644 --- a/tests/translator/output/aws-us-gov/api_with_gateway_responses_minimal.json +++ b/tests/translator/output/aws-us-gov/api_with_gateway_responses_minimal.json @@ -1,79 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -93,20 +39,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ExplicitApiDeployment40cf320ad7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 40cf320ad73ddd78e84f215f113837bc07a54769", "RestApiId": { "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: 40cf320ad73ddd78e84f215f113837bc07a54769", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment40cf320ad7" @@ -115,28 +61,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_gateway_responses_string_status_code.json b/tests/translator/output/aws-us-gov/api_with_gateway_responses_string_status_code.json index 936b9c68cc..7bfac8335f 100644 --- a/tests/translator/output/aws-us-gov/api_with_gateway_responses_string_status_code.json +++ b/tests/translator/output/aws-us-gov/api_with_gateway_responses_string_status_code.json @@ -1,89 +1,25 @@ { "Resources": { - "Function": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiDeployment929d2126a7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 929d2126a7a3b228757ccb4aa5e896c1bd5c76e8", - "StageName": "Stage" - } - }, - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "responses": {} + } } } }, @@ -91,9 +27,9 @@ "x-amazon-apigateway-gateway-responses": { "UNAUTHORIZED": { "responseParameters": { - "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'", + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'", "gatewayresponse.header.Access-Control-Expose-Headers": "'WWW-Authenticate'", - "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + "gatewayresponse.header.WWW-Authenticate": "'Bearer realm=\"admin\"'" }, "responseTemplates": {}, "statusCode": "401" @@ -108,10 +44,20 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment929d2126a7": { + "Properties": { + "Description": "RestApi deployment id: 929d2126a7a3b228757ccb4aa5e896c1bd5c76e8", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment929d2126a7" @@ -120,28 +66,82 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Function": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "Function" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ExplicitApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_identity_intrinsic.json b/tests/translator/output/aws-us-gov/api_with_identity_intrinsic.json index 098ebbf10e..e61205baf7 100644 --- a/tests/translator/output/aws-us-gov/api_with_identity_intrinsic.json +++ b/tests/translator/output/aws-us-gov/api_with_identity_intrinsic.json @@ -5,24 +5,21 @@ }, "Resources": { "APIGateway": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": {}, - "swagger": "2.0", "securityDefinitions": { "SomeAuthorizer": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", "authorizerResultTtlInSeconds": { "Fn::If": [ "isProd", @@ -30,7 +27,6 @@ 0 ] }, - "identitySource": "method.request.header.Accept", "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -38,11 +34,14 @@ "__FunctionArn__": "SomeArn" } ] - } + }, + "identitySource": "method.request.header.Accept", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -52,24 +51,36 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "APIGatewayDeploymentbbcece046c": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: bbcece046c6ecd35f10c6ba88cf762d87ef35e8a", "RestApiId": { "Ref": "APIGateway" }, - "Description": "RestApi deployment id: bbcece046c6ecd35f10c6ba88cf762d87ef35e8a", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "APIGatewayProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "APIGatewayDeploymentbbcece046c" + }, + "RestApiId": { + "Ref": "APIGateway" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "APIGatewaySomeAuthorizerAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": "SomeArn", + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", @@ -80,19 +91,8 @@ } ] } - } - }, - "APIGatewayProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "APIGatewayDeploymentbbcece046c" - }, - "RestApiId": { - "Ref": "APIGateway" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_if_conditional_with_resource_policy.json b/tests/translator/output/aws-us-gov/api_with_if_conditional_with_resource_policy.json index 1b1b52d700..8e8cd588e2 100644 --- a/tests/translator/output/aws-us-gov/api_with_if_conditional_with_resource_policy.json +++ b/tests/translator/output/aws-us-gov/api_with_if_conditional_with_resource_policy.json @@ -8,8 +8,106 @@ } }, "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/one": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/three": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/two": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Fn::If": [ + "C1", + { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment6c75921e70": { + "Properties": { + "Description": "RestApi deployment id: 6c75921e70c9e79fa98611cad36e4af5d3e002d6", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -29,40 +127,10 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "ExplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -80,10 +148,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "ExplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -101,10 +169,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPutHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -113,7 +181,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", { "__ApiId__": { "Ref": "ExplicitApi" @@ -122,10 +190,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPutHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -134,7 +202,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", { "__ApiId__": { "Ref": "ExplicitApi" @@ -143,109 +211,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ExplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Fn::If": [ - "C1", - { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - }, - { - "Ref": "AWS::NoValue" - } - ] - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment6c75921e70": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 6c75921e70c9e79fa98611cad36e4af5d3e002d6", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment6c75921e70" @@ -254,7 +253,8 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_incompatible_stage_name.json b/tests/translator/output/aws-us-gov/api_with_incompatible_stage_name.json index 4f1c1e6b36..cc74f7055f 100644 --- a/tests/translator/output/aws-us-gov/api_with_incompatible_stage_name.json +++ b/tests/translator/output/aws-us-gov/api_with_incompatible_stage_name.json @@ -1,304 +1,304 @@ { "Resources": { - "UnderscoreApiStageb34d3ad84e": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "UnderscoreApiDeployment94459366c6" - }, - "RestApiId": { - "Ref": "UnderscoreApi" - }, - "StageName": "hoge_fuga" - } - }, - "UnderscoreApi": { - "Type": "AWS::ApiGateway::RestApi", + "HyphenApi": { "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UnderscoreFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HyphenFunction.Arn}/invocations" + } } } } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "UnderscoreFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "HyphenFunctionGetHtmlPermission0c8ecc62cb": { - "Type": "AWS::Lambda::Permission", + "HyphenApiDeploymente60ebb9f56": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HyphenFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "HyphenApi" - } - ] - } - } - }, + "Description": "RestApi deployment id: e60ebb9f56220ac12550230674d09ed8085afc74", + "RestApiId": { + "Ref": "HyphenApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "HyphenApiStage0c8ecc62cb": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "HyphenApiDeploymente60ebb9f56" - }, + }, "RestApiId": { "Ref": "HyphenApi" - }, + }, "StageName": "hoge-fuga" - } - }, - "UnderscoreFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HyphenFunction": { "Properties": { - "Handler": "index.gethtml", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "UnderscoreFunctionRole", + "HyphenFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "UnderscoreFunctionGetHtmlPermissionb34d3ad84e": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HyphenFunctionGetHtmlPermission0c8ecc62cb": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "UnderscoreFunction" - }, + "Ref": "HyphenFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "UnderscoreApi" + "__ApiId__": "HyphenApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HyphenFunction": { - "Type": "AWS::Lambda::Function", + "HyphenFunctionRole": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HyphenFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HyphenApiDeploymente60ebb9f56": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HyphenApi" - }, - "Description": "RestApi deployment id: e60ebb9f56220ac12550230674d09ed8085afc74", - "StageName": "Stage" - } - }, - "UnderscoreApiDeployment94459366c6": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "UnderscoreApi" - }, - "Description": "RestApi deployment id: 94459366c6f9a344235ddf7db2a7cd5115d60da4", - "StageName": "Stage" - } - }, - "HyphenApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "UnderscoreApi": { "Properties": { "Body": { + "definitions": { + "user": { + "properties": { + "username": { + "type": "string" + } + }, + "type": "object" + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HyphenFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": true, - "in": "body", - "name": "user", + "in": "body", + "name": "user", + "required": true, "schema": { "$ref": "#/definitions/user" } } - ] - } - } - }, - "swagger": "2.0", - "definitions": { - "user": { - "type": "object", - "properties": { - "username": { - "type": "string" + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${UnderscoreFunction.Arn}/invocations" + } } } } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "HyphenFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "UnderscoreApiDeployment94459366c6": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Description": "RestApi deployment id: 94459366c6f9a344235ddf7db2a7cd5115d60da4", + "RestApiId": { + "Ref": "UnderscoreApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "UnderscoreApiStageb34d3ad84e": { + "Properties": { + "DeploymentId": { + "Ref": "UnderscoreApiDeployment94459366c6" + }, + "RestApiId": { + "Ref": "UnderscoreApi" + }, + "StageName": "hoge_fuga" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "UnderscoreFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "UnderscoreFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "UnderscoreFunctionGetHtmlPermissionb34d3ad84e": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "UnderscoreFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "UnderscoreApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "UnderscoreFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_ip_range_blacklist.json b/tests/translator/output/aws-us-gov/api_with_ip_range_blacklist.json index d89da5b7f0..997f5b5fef 100644 --- a/tests/translator/output/aws-us-gov/api_with_ip_range_blacklist.json +++ b/tests/translator/output/aws-us-gov/api_with_ip_range_blacklist.json @@ -1,196 +1,196 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment7a90608509" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment7a90608509": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 7a906085093a57bc5b444a0158449c6725a507cc", - "StageName": "Stage" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/get": { "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", - { - "__Stage__": "Prod" - } - ] - } - ], - "Effect": "Allow", + "Action": "execute-api:Invoke", + "Effect": "Allow", "Principal": { "AWS": [ "12345" ] - } - }, - { - "Action": "execute-api:Invoke", + }, "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": "*" - }, + ] + }, { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "IpAddress": { "aws:SourceIp": [ "1.2.3.4" ] } - }, - "Principal": "*" + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/PUT/get", + { + "__Stage__": "Prod" + } + ] + } + ] } - ] + ], + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment7a90608509": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: 7a906085093a57bc5b444a0158449c6725a507cc", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment7a90608509" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_ip_range_whitelist.json b/tests/translator/output/aws-us-gov/api_with_ip_range_whitelist.json index 5750d7cf76..4c05e3a5a3 100644 --- a/tests/translator/output/aws-us-gov/api_with_ip_range_whitelist.json +++ b/tests/translator/output/aws-us-gov/api_with_ip_range_whitelist.json @@ -1,199 +1,199 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment05e180d91b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05e180d91bfb84481403ba5b028afe1db84437dc", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionApiPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment05e180d91b" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/get": { "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": "2.0", + }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Allow", - "Principal": "*" - }, + ] + }, { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { - "NotIpAddress": { + "IpAddress": { "aws:SourceIp": [ "1.2.3.4" ] } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" + ] } - ] + ], + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05e180d91b": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: 05e180d91bfb84481403ba5b028afe1db84437dc", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment05e180d91b" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_method_aws_iam_auth.json b/tests/translator/output/aws-us-gov/api_with_method_aws_iam_auth.json index 06cbf8a55f..2ae607d45c 100644 --- a/tests/translator/output/aws-us-gov/api_with_method_aws_iam_auth.json +++ b/tests/translator/output/aws-us-gov/api_with_method_aws_iam_auth.json @@ -1,7 +1,128 @@ { "Resources": { + "MyApiWithoutAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "post": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + }, + "put": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + }, + "/any/one": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "AWS_IAM": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": "arn:aws:iam::*:user/*", + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithoutAuthDeployment60e94c7d4c": { + "Properties": { + "Description": "RestApi deployment id: 60e94c7d4c7027bdd55b188a3e78764ec1fe52da", + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithoutAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithoutAuthDeployment60e94c7d4c" + }, + "RestApiId": { + "Ref": "MyApiWithoutAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionWithAwsIamAuth": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -21,40 +142,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionWithAwsIamAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +154,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -72,10 +163,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndCustomInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +175,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -93,10 +184,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAndDefaultInvokeRolePermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +196,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/one", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -114,10 +205,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithAwsIamAuthMyApiWithAwsIamAuthPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +217,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/one", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "MyApiWithoutAuth" @@ -135,129 +226,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithoutAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionWithAwsIamAuthRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "rn:aws:iam::123:role/AUTH_AWS_IAM" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - }, - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } - ] - } - }, - "/any/one": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionWithAwsIamAuth.Arn}/invocations" - }, - "credentials": "arn:aws:iam::*:user/*" - }, - "responses": {}, - "security": [ - { - "AWS_IAM": [] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - }, - "securityDefinitions": { - "AWS_IAM": { - "x-amazon-apigateway-authtype": "awsSigv4", - "type": "apiKey", - "name": "Authorization", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiWithoutAuthDeployment60e94c7d4c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 60e94c7d4c7027bdd55b188a3e78764ec1fe52da", - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Stage" - } - }, - "MyApiWithoutAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithoutAuthDeployment60e94c7d4c" - }, - "RestApiId": { - "Ref": "MyApiWithoutAuth" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_method_settings.json b/tests/translator/output/aws-us-gov/api_with_method_settings.json index 58f29e3093..223b347b26 100644 --- a/tests/translator/output/aws-us-gov/api_with_method_settings.json +++ b/tests/translator/output/aws-us-gov/api_with_method_settings.json @@ -1,193 +1,193 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "MethodSettings": [ + { + "DataTraceEnabled": true, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": true, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "MethodSettings": [ - { - "HttpMethod": "*", - "MetricsEnabled": true, - "ResourcePath": "/*", - "DataTraceEnabled": true, - "LoggingLevel": "INFO" - } - ], - "RestApiId": { - "Ref": "ExplicitApi" - }, - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment5b2cb4ba8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "MethodSettings": [ + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "HttpMethod": "*", - "MetricsEnabled": true, - "ResourcePath": "/*", - "DataTraceEnabled": true, - "LoggingLevel": "INFO" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" - }, - "StageName": "Prod" - } - }, + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5b2cb4ba8f": { + "Properties": { + "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" + }, + "MethodSettings": [ + { + "DataTraceEnabled": true, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": true, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_minimum_compression_size.json b/tests/translator/output/aws-us-gov/api_with_minimum_compression_size.json index 5dc49fdfe4..84b076abe6 100644 --- a/tests/translator/output/aws-us-gov/api_with_minimum_compression_size.json +++ b/tests/translator/output/aws-us-gov/api_with_minimum_compression_size.json @@ -1,177 +1,177 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "MinimumCompressionSize": 256, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "ImplicitApiFunctionRole", + "ImplicitApiFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "MinimumCompressionSize": 256, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment5b2cb4ba8f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", - "StageName": "Stage" - } - }, - "ExplicitApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, - "MinimumCompressionSize": 1024, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, + "MinimumCompressionSize": 1024, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment5b2cb4ba8f": { + "Properties": { + "Description": "RestApi deployment id: 5b2cb4ba8fce8a9445b1914c6c6fbeef81a9075a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment5b2cb4ba8f" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_mode.json b/tests/translator/output/aws-us-gov/api_with_mode.json index bcee5b4e42..7e9a451bac 100644 --- a/tests/translator/output/aws-us-gov/api_with_mode.json +++ b/tests/translator/output/aws-us-gov/api_with_mode.json @@ -1,81 +1,9 @@ { "Resources": { - "FunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "Api" - }, - "StageName": "Prod" - } - }, - "FunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "Api" - } - ] - } - } - }, - "ApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, "Api": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "BodyS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "webpage_swagger.json" }, "Description": "my description", @@ -88,30 +16,102 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "Api", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_no_properties.json b/tests/translator/output/aws-us-gov/api_with_no_properties.json index 9d09d19231..49425caf3d 100644 --- a/tests/translator/output/aws-us-gov/api_with_no_properties.json +++ b/tests/translator/output/aws-us-gov/api_with_no_properties.json @@ -1,7 +1,54 @@ { "Resources": { + "HTTPApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + } + } + } + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "HTTPApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "HTTPApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +68,31 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "HtmlFunctionGetHtmlPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HTTPApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +105,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,74 +117,8 @@ "Value": "SAM" } ] - } - }, - "HtmlFunctionGetHtmlPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__ApiId__": "HTTPApi", - "__Stage__": "*" - } - ] - } - } - }, - "HTTPApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "openapi": "3.0.1", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "payloadFormatVersion": "2.0", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" - } - }, - "responses": {} - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, - "HTTPApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HTTPApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_open_api_version.json b/tests/translator/output/aws-us-gov/api_with_open_api_version.json index 8efe48e719..69357704cd 100644 --- a/tests/translator/output/aws-us-gov/api_with_open_api_version.json +++ b/tests/translator/output/aws-us-gov/api_with_open_api_version.json @@ -1,7 +1,50 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {} + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymentd9a0f2ae4f": { + "Properties": { + "Description": "RestApi deployment id: d9a0f2ae4fe2d97b9b91644934a878b6a08cf1c3", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymentd9a0f2ae4f" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +64,10 @@ "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +76,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +85,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +97,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,187 +106,173 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {}, - "openapi": "3.0.1" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeploymentd9a0f2ae4f": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: d9a0f2ae4fe2d97b9b91644934a878b6a08cf1c3", - "RestApiId": { - "Ref": "ExplicitApi" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymentd9a0f2ae4f" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", - "x-amazon-apigateway-integration": { - "type": "mock", - "requestTemplates": { - "application/json": "{\n \"statusCode\" : 200\n}\n" - }, - "responses": { - "default": { - "statusCode": "200", - "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" - }, - "responseTemplates": { - "application/json": "{}\n" - } - } - } - }, "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } } } - } - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } }, - "responses": {} - }, - "options": { "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } + }, + "statusCode": "200" } - } - }, + }, + "type": "mock" + } + } + }, + "/any": { + "options": { "responses": { "200": { "description": "Default response for CORS method", "headers": { - "Access-Control-Allow-Origin": { + "Access-Control-Allow-Methods": { "schema": { "type": "string" } }, - "Access-Control-Allow-Methods": { + "Access-Control-Allow-Origin": { "schema": { "type": "string" } } } } + }, + "summary": "CORS support", + "x-amazon-apigateway-integration": { + "requestTemplates": { + "application/json": "{\n \"statusCode\" : 200\n}\n" + }, + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "*" + }, + "responseTemplates": { + "application/json": "{}\n" + }, + "statusCode": "200" + } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } } } } - }, - "openapi": "3.0.1" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + } }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymentcecfa4a1a7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: cecfa4a1a7d95801494452e34ba03f6e033c8f5a", "RestApiId": { "Ref": "ServerlessRestApi" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentcecfa4a1a7" @@ -282,7 +281,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_open_api_version_2.json b/tests/translator/output/aws-us-gov/api_with_open_api_version_2.json index 6f75e51c9d..b024c43d94 100644 --- a/tests/translator/output/aws-us-gov/api_with_open_api_version_2.json +++ b/tests/translator/output/aws-us-gov/api_with_open_api_version_2.json @@ -1,7 +1,50 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment4154e1c30c": { + "Properties": { + "Description": "RestApi deployment id: 4154e1c30c97469d4946280461125dbfd4324f15", + "RestApiId": { + "Ref": "ExplicitApi" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment4154e1c30c" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +64,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionAnyHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +76,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +85,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +97,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,191 +106,177 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {} - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment4154e1c30c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 4154e1c30c97469d4946280461125dbfd4324f15", - "RestApiId": { - "Ref": "ExplicitApi" - } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment4154e1c30c" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'" + "method.response.header.Access-Control-Allow-Methods": "'GET,OPTIONS'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } - } + }, + "type": "mock" } } }, "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - }, "options": { - "summary": "CORS support", "consumes": [ "application/json" ], "produces": [ "application/json" ], + "responses": { + "200": { + "description": "Default response for CORS method", + "headers": { + "Access-Control-Allow-Methods": { + "type": "string" + }, + "Access-Control-Allow-Origin": { + "type": "string" + } + } + } + }, + "summary": "CORS support", "x-amazon-apigateway-integration": { - "type": "mock", "requestTemplates": { "application/json": "{\n \"statusCode\" : 200\n}\n" }, "responses": { "default": { - "statusCode": "200", "responseParameters": { - "method.response.header.Access-Control-Allow-Origin": "*", - "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'" + "method.response.header.Access-Control-Allow-Methods": "'DELETE,GET,HEAD,OPTIONS,PATCH,POST,PUT'", + "method.response.header.Access-Control-Allow-Origin": "*" }, "responseTemplates": { "application/json": "{}\n" - } - } - } - }, - "responses": { - "200": { - "description": "Default response for CORS method", - "headers": { - "Access-Control-Allow-Origin": { - "type": "string" }, - "Access-Control-Allow-Methods": { - "type": "string" - } + "statusCode": "200" } + }, + "type": "mock" + } + }, + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeploymenta4a375efae": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: a4a375efae9da8fb80b2ea99cd0b1040f292cdf3", "RestApiId": { "Ref": "ServerlessRestApi" } - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymenta4a375efae" @@ -286,7 +285,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_openapi_definition_body_no_flag.json b/tests/translator/output/aws-us-gov/api_with_openapi_definition_body_no_flag.json index ac3cc1ea5b..d95ca5396d 100644 --- a/tests/translator/output/aws-us-gov/api_with_openapi_definition_body_no_flag.json +++ b/tests/translator/output/aws-us-gov/api_with_openapi_definition_body_no_flag.json @@ -1,277 +1,277 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ExplicitApiDeployment9252467a1e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9252467a1edc49ba35cb258640f5e3734cc9fab1", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "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" - } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.1.1", "components": { "securitySchemes": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.1.1", + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "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" + } + } + } + } } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment9252467a1e": { "Properties": { + "Description": "RestApi deployment id: 9252467a1edc49ba35cb258640f5e3734cc9fab1", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentc969c99f9d" - } - } - }, + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment9252467a1e" + }, "RestApiId": { "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", + }, + "StageName": "SomeStage", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment9252467a1e" } - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiDeploymentc969c99f9d": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 } - }, + }, "Schema": [ { - "AttributeDataType": "String", - "Required": false, - "Name": "email" + "AttributeDataType": "String", + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, + }, + "Type": "AWS::Cognito::UserPool" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "MyCognitoAuth": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentc969c99f9d": { + "Properties": { + "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentc969c99f9d" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/api_with_path_parameters.json b/tests/translator/output/aws-us-gov/api_with_path_parameters.json index 69c7f9408c..d2df294079 100644 --- a/tests/translator/output/aws-us-gov/api_with_path_parameters.json +++ b/tests/translator/output/aws-us-gov/api_with_path_parameters.json @@ -1,7 +1,45 @@ { "Resources": { + "HtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "HtmlApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "HtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +59,10 @@ "Value": "SAM" } ] - } - }, - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "HtmlFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -70,10 +78,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -89,46 +97,38 @@ } ] } - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "RestApiId": { - "Ref": "HtmlApi" - }, - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "HtmlFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "HtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "HtmlApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_resource_policy.json b/tests/translator/output/aws-us-gov/api_with_resource_policy.json index bb2272c170..f1bf5fa161 100644 --- a/tests/translator/output/aws-us-gov/api_with_resource_policy.json +++ b/tests/translator/output/aws-us-gov/api_with_resource_policy.json @@ -1,7 +1,97 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/one": { + "get": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/three": { + "put": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + }, + "/two": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Action": "execute-api:Invoke", + "Resource": [ + "execute-api:/*/*/*" + ] + }, + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment5c27484b15": { + "Properties": { + "Description": "RestApi deployment id: 5c27484b15a09a4bdfefb251767543b7b351a50d", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +111,10 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "ExplicitApiFunctionAnyHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,10 +132,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "ExplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -93,10 +153,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPutHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPostHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +165,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", { "__ApiId__": { "Ref": "ExplicitApi" @@ -114,10 +174,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApiFunctionPostHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ExplicitApiFunctionPutHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -126,7 +186,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/two", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/three", { "__ApiId__": { "Ref": "ExplicitApi" @@ -135,101 +195,40 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ExplicitApiFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} - } - }, - "/any": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" - } - }, - "responses": {} + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - }, - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Action": "execute-api:Invoke", - "Resource": [ - "execute-api:/*/*/*" - ] - } - } + ], + "Version": "2012-10-17" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment5c27484b15": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 5c27484b15a09a4bdfefb251767543b7b351a50d", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ExplicitApiDeployment5c27484b15" @@ -238,7 +237,8 @@ "Ref": "ExplicitApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_resource_policy_global.json b/tests/translator/output/aws-us-gov/api_with_resource_policy_global.json index b690b02710..8fa11eb931 100644 --- a/tests/translator/output/aws-us-gov/api_with_resource_policy_global.json +++ b/tests/translator/output/aws-us-gov/api_with_resource_policy_global.json @@ -2,247 +2,247 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Parameters": { "StageName": { - "Default": "MyOwnStage", + "Default": "MyOwnStage", "Type": "String" } - }, + }, "Resources": { "AnotherApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0", + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": { "Fn::If": [ - "C1", + "C1", { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*/*/*" ] - }, + }, { - "Action": "execute-api:Another", + "Action": "execute-api:Another", "Resource": [ "execute-api:/*/*/*" ] } ] - } + }, + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ExplicitApiDeploymenta5a5c4e3ff": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: a5a5c4e3ff6901cf27436628359ed20300d34aa4", - "StageName": "Stage" - } - }, - "ExplicitApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeploymenta5a5c4e3ff" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": { - "Ref": "StageName" - } - } - }, - "ExplicitApiFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "ExplicitApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ExplicitApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "AnotherApiDeploymentfdf1387e0a": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: fdf1387e0a89fa15996401a79284cdaaf2c43844", "RestApiId": { "Ref": "AnotherApi" - }, - "Description": "RestApi deployment id: fdf1387e0a89fa15996401a79284cdaaf2c43844", + }, "StageName": "Stage" - } - }, - "ExplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ExplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ExplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::ApiGateway::Deployment" + }, "AnotherApiStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "AnotherApiDeploymentfdf1387e0a" - }, + }, "RestApiId": { "Ref": "AnotherApi" - }, + }, "StageName": { "Ref": "StageName" } - } - }, + }, + "Type": "AWS::ApiGateway::Stage" + }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ExplicitApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, - "swagger": 2.0, + }, + "swagger": 2.0, "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sts:AssumeRole", - "Effect": "Allow", + "Action": "sts:AssumeRole", + "Effect": "Allow", "Principal": { "Service": "lambda.amazonaws.com" } - }, + }, { "Fn::If": [ - "C1", + "C1", { - "Action": "execute-api:Invoke", + "Action": "execute-api:Invoke", "Resource": [ "execute-api:/*/*/*" ] - }, + }, { - "Action": "execute-api:Blah", + "Action": "execute-api:Blah", "Resource": [ "execute-api:/*/*/*" ] } ] } - ] + ], + "Version": "2012-10-17" } - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeploymenta5a5c4e3ff": { + "Properties": { + "Description": "RestApi deployment id: a5a5c4e3ff6901cf27436628359ed20300d34aa4", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ExplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ExplicitApiFunctionGetHtmlPermissionStage": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ExplicitApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "ExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ExplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ExplicitApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeploymenta5a5c4e3ff" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": { + "Ref": "StageName" + } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_resource_policy_global_implicit.json b/tests/translator/output/aws-us-gov/api_with_resource_policy_global_implicit.json index 6e774b9232..0c5b423a9a 100644 --- a/tests/translator/output/aws-us-gov/api_with_resource_policy_global_implicit.json +++ b/tests/translator/output/aws-us-gov/api_with_resource_policy_global_implicit.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +20,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MinimalFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MinimalFunctionAddItemAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -63,7 +32,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/add", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -72,10 +41,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MinimalFunctionAddItemAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MinimalFunctionAddItemPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +53,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/add", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,47 +62,76 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MinimalFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/any/add": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MinimalFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { "Action": "execute-api:Invoke", @@ -147,31 +145,32 @@ "execute-api:/*/*/*" ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment96851cbcc5": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 96851cbcc51bf1b545cdaf293a4c302a35a7e355", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment96851cbcc5" @@ -180,7 +179,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_resource_refs.json b/tests/translator/output/aws-us-gov/api_with_resource_refs.json index 488db17e93..1aae7997d2 100644 --- a/tests/translator/output/aws-us-gov/api_with_resource_refs.json +++ b/tests/translator/output/aws-us-gov/api_with_resource_refs.json @@ -1,7 +1,67 @@ { + "Outputs": { + "ExplicitApiDeployment": { + "Value": { + "Ref": "MyApiDeployment359f256a3b" + } + }, + "ExplicitApiStage": { + "Value": { + "Ref": "MyApifooStage" + } + }, + "ImplicitApiDeployment": { + "Value": { + "Ref": "ServerlessRestApiDeployment8d814b9726" + } + }, + "ImplicitApiStage": { + "Value": { + "Ref": "ServerlessRestApiProdStage" + } + } + }, "Resources": { + "MyApi": { + "Properties": { + "Body": { + "a": "swagger", + "this": "is" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment359f256a3b": { + "Properties": { + "Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApifooStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment359f256a3b" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "foo" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,40 +81,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionGetHtmlAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,10 +102,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -93,107 +123,98 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "swagger" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiDeployment359f256a3b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 359f256a3b3ff2e1102e335a4d603f02df9b4988", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyApifooStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment359f256a3b" - }, - "RestApiId": { - "Ref": "MyApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "foo" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/html": { - "get": { + "/any/html": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/html": { - "x-amazon-apigateway-any-method": { + "/html": { + "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment8d814b9726": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 8d814b9726e535cb84c0737ea3d4f9b02de35b06", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment8d814b9726" @@ -202,29 +223,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } - } - }, - "Outputs": { - "ImplicitApiDeployment": { - "Value": { - "Ref": "ServerlessRestApiDeployment8d814b9726" - } - }, - "ImplicitApiStage": { - "Value": { - "Ref": "ServerlessRestApiProdStage" - } - }, - "ExplicitApiDeployment": { - "Value": { - "Ref": "MyApiDeployment359f256a3b" - } - }, - "ExplicitApiStage": { - "Value": { - "Ref": "MyApifooStage" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_security_definition_and_components.json b/tests/translator/output/aws-us-gov/api_with_security_definition_and_components.json index 665cedf944..66d868cdc1 100644 --- a/tests/translator/output/aws-us-gov/api_with_security_definition_and_components.json +++ b/tests/translator/output/aws-us-gov/api_with_security_definition_and_components.json @@ -1,7 +1,90 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "schemas": { + "Error": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "Object" + } + }, + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment195f5bf5d0": { + "Properties": { + "Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment195f5bf5d0" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +104,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +122,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,91 +134,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiDeployment195f5bf5d0": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 195f5bf5d07bf7af9c64f0649d2724425b106350", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment195f5bf5d0" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - }, - "schemas": { - "Error": { - "type": "Object", - "properties": { - "message": { - "type": "string" - } - } - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_security_definition_and_no_components.json b/tests/translator/output/aws-us-gov/api_with_security_definition_and_no_components.json index fd188a2b32..d4aa3e8149 100644 --- a/tests/translator/output/aws-us-gov/api_with_security_definition_and_no_components.json +++ b/tests/translator/output/aws-us-gov/api_with_security_definition_and_no_components.json @@ -1,7 +1,80 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment407993a935": { + "Properties": { + "Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment407993a935" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +94,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +112,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,81 +124,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment407993a935" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment407993a935": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 407993a9358b76c8e74599b2c0b914409ee0da64", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_security_definition_and_none_components.json b/tests/translator/output/aws-us-gov/api_with_security_definition_and_none_components.json index 83fb7900ca..c067aa82cd 100644 --- a/tests/translator/output/aws-us-gov/api_with_security_definition_and_none_components.json +++ b/tests/translator/output/aws-us-gov/api_with_security_definition_and_none_components.json @@ -1,7 +1,80 @@ { "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + null + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "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" + } + } + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment61b3921bb7": { + "Properties": { + "Description": "RestApi deployment id: 61b3921bb7522c20a8e0de1d24c974267f3ec17b", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment61b3921bb7" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +94,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +112,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,81 +124,8 @@ "Value": "SAM" } ] - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment61b3921bb7" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "ExplicitApiDeployment61b3921bb7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 61b3921bb7522c20a8e0de1d24c974267f3ec17b", - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Stage" - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/{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": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "CognitoAuthorizer": { - "x-amazon-apigateway-authtype": "cognito_user_pools", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - null - ], - "type": "cognito_user_pools" - }, - "in": "header" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_source_vpc_blacklist.json b/tests/translator/output/aws-us-gov/api_with_source_vpc_blacklist.json index 2bba5cd9b1..e4c5c89680 100644 --- a/tests/translator/output/aws-us-gov/api_with_source_vpc_blacklist.json +++ b/tests/translator/output/aws-us-gov/api_with_source_vpc_blacklist.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -20,40 +19,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionApiAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -71,10 +40,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -92,51 +61,81 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any/get": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/get": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -146,12 +145,19 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Condition": { + "StringEquals": { + "aws:SourceVpce": [ + "vpce-3456" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -161,19 +167,12 @@ } ] } - ], - "Principal": "*", - "Condition": { - "StringEquals": { - "aws:SourceVpce": [ - "vpce-3456" - ] - } - } + ] }, { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -183,12 +182,19 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Condition": { + "StringEquals": { + "aws:SourceVpce": [ + "vpce-3456" + ] + } + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -198,41 +204,34 @@ } ] } - ], - "Principal": "*", - "Condition": { - "StringEquals": { - "aws:SourceVpce": [ - "vpce-3456" - ] - } - } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment23380bf0b1": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 23380bf0b1dd78bf73e4d0173752489c37262bc4", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment23380bf0b1" @@ -241,7 +240,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_source_vpc_whitelist.json b/tests/translator/output/aws-us-gov/api_with_source_vpc_whitelist.json index dd73d0ebc3..58f8edc259 100644 --- a/tests/translator/output/aws-us-gov/api_with_source_vpc_whitelist.json +++ b/tests/translator/output/aws-us-gov/api_with_source_vpc_whitelist.json @@ -1,13 +1,57 @@ { "Parameters": { "Vpc1": { - "Type": "String", - "Default": "vpc-1234" + "Default": "vpc-1234", + "Type": "String" } }, "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment5332c373d4": { + "Properties": { + "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment5332c373d4" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" @@ -26,40 +70,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionFetchAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionApiAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -68,7 +82,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/fetch", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/get", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -77,10 +91,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionApiAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionApiPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -89,7 +103,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/get", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -98,10 +112,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionFetchPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionFetchAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -110,7 +124,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/fetch", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -119,10 +133,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionApiPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionFetchPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -131,7 +145,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/get", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -140,120 +154,105 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionRole": { "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - }, - "paths": {} - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiDeployment5332c373d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment5332c373d4" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/get": { - "put": { + "/any/fetch": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/any/get": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, "/fetch": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/any/fetch": { - "x-amazon-apigateway-any-method": { + "/get": { + "put": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" } - }, - "responses": {} + } } } }, + "swagger": "2.0", "x-amazon-apigateway-policy": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -263,23 +262,10 @@ } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/PUT/get", - { - "__Stage__": "Prod" - } - ] - } - ], - "Principal": "*", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -287,26 +273,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/*/any/get", + "execute-api:/${__Stage__}/PUT/get", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -316,8 +300,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -325,26 +311,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/fetch", + "execute-api:/${__Stage__}/*/any/get", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -354,8 +338,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -363,26 +349,24 @@ "vpc-5678" ] } - } - }, - { - "Effect": "Allow", - "Action": "execute-api:Invoke", + }, + "Effect": "Deny", + "Principal": "*", "Resource": [ { "Fn::Sub": [ - "execute-api:/${__Stage__}/*/any/fetch", + "execute-api:/${__Stage__}/POST/fetch", { "__Stage__": "Prod" } ] } - ], - "Principal": "*" + ] }, { - "Effect": "Deny", "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", "Resource": [ { "Fn::Sub": [ @@ -392,8 +376,10 @@ } ] } - ], - "Principal": "*", + ] + }, + { + "Action": "execute-api:Invoke", "Condition": { "StringNotEquals": { "aws:SourceVpc": [ @@ -401,33 +387,46 @@ "vpc-5678" ] } - } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/*/any/fetch", + { + "__Stage__": "Prod" + } + ] + } + ] } - ] + ], + "Version": "2012-10-17" } }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment7ac89a5c9d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 7ac89a5c9dea985081529cc0baa2eeecd04a3981", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment7ac89a5c9d" @@ -436,7 +435,8 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_stage_tags.json b/tests/translator/output/aws-us-gov/api_with_stage_tags.json index 1e99128862..2cd544ace2 100644 --- a/tests/translator/output/aws-us-gov/api_with_stage_tags.json +++ b/tests/translator/output/aws-us-gov/api_with_stage_tags.json @@ -1,75 +1,75 @@ { "Parameters": { "TagValueParam": { - "Default": "value", + "Default": "value", "Type": "String" } - }, + }, "Resources": { - "MyApiWithStageTagsDeployment5332c373d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithStageTags" - }, - "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", - "StageName": "Stage" - } - }, "MyApiWithStageTags": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "paths": {}, + }, + "version": "1.0" + }, + "paths": {}, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithStageTagsDeployment5332c373d4": { + "Properties": { + "Description": "RestApi deployment id: 5332c373d45c69e6c0f562b4a419aa8eb311adc7", + "RestApiId": { + "Ref": "MyApiWithStageTags" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "MyApiWithStageTagsProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithStageTagsDeployment5332c373d4" - }, + }, "RestApiId": { "Ref": "MyApiWithStageTags" - }, - "StageName": "Prod", + }, + "StageName": "Prod", "Tags": [ { - "Value": "TagValue1", - "Key": "TagKey1" - }, + "Key": "TagKey1", + "Value": "TagValue1" + }, { - "Value": "", - "Key": "TagKey2" - }, + "Key": "TagKey2", + "Value": "" + }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" - }, + } + }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ] - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_swagger_and_openapi_with_auth.json b/tests/translator/output/aws-us-gov/api_with_swagger_and_openapi_with_auth.json index b5f056d542..103de42472 100644 --- a/tests/translator/output/aws-us-gov/api_with_swagger_and_openapi_with_auth.json +++ b/tests/translator/output/aws-us-gov/api_with_swagger_and_openapi_with_auth.json @@ -1,28 +1,95 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", + "ExplicitApi": { "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.1.1", + "paths": { + "/": { + "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], + "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" + } + } + } + } + }, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": [ + "MyUserPool", + "Arn" + ] + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + }, + "swagger": 2.0 }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment7c4f7dda23": { + "Properties": { + "Description": "RestApi deployment id: 7c4f7dda23acd71e4a653861510d82ad7809e562", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiSomeStageStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment7c4f7dda23" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "SomeStage", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -42,40 +109,10 @@ "Value": "SAM" } ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, - "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -84,7 +121,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -93,10 +130,10 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ImplicitApiFunctionGetHtmlAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ImplicitApiFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -105,7 +142,7 @@ "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__ApiId__": { "Ref": "ServerlessRestApi" @@ -114,152 +151,111 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ImplicitApiFunctionRole": { "Properties": { - "Body": { - "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": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "MyCognitoAuth": [] - } - ] - } - } - }, - "securityDefinitions": { - "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", - "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", - "providerARNs": [ - { - "Fn::GetAtt": [ - "MyUserPool", - "Arn" - ] - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } - } - }, - "Name": "some api", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ExplicitApiDeployment7c4f7dda23": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 7c4f7dda23acd71e4a653861510d82ad7809e562", - "RestApiId": { - "Ref": "ExplicitApi" + ], + "Version": "2012-10-17" }, - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", + "MyUserPool": { "Properties": { - "CacheClusterEnabled": true, - "CacheClusterSize": "1.6", - "DeploymentId": { - "Ref": "ExplicitApiDeployment7c4f7dda23" - }, - "RestApiId": { - "Ref": "ExplicitApi" + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } }, - "StageName": "SomeStage", - "Variables": { - "SomeVar": "Value" - } - } + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] - } - }, - "/any": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, + } + } + }, + "/any": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "MyCognitoAuth": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -267,34 +263,37 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, - "Name": "some api", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Name": "some api", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "ServerlessRestApiDeployment05a3d3687d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 05a3d3687d4bfb804b237d40817879c6559ac61c", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "CacheClusterEnabled": true, "CacheClusterSize": "1.6", @@ -308,7 +307,8 @@ "Variables": { "SomeVar": "Value" } - } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_swagger_authorizer_none.json b/tests/translator/output/aws-us-gov/api_with_swagger_authorizer_none.json index c65310adc0..ae54a69577 100644 --- a/tests/translator/output/aws-us-gov/api_with_swagger_authorizer_none.json +++ b/tests/translator/output/aws-us-gov/api_with_swagger_authorizer_none.json @@ -1,311 +1,56 @@ { "Resources": { - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "UserPoolName": "UserPoolName", - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "UsernameAttributes": [ - "email" - ], - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ] - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFnRole", - "Arn" - ] - }, - "Runtime": "nodejs8.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyFnCognitoAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnCognitoPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", - { - "__ApiId__": { - "Ref": "MyApiWithCognitoAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaRequestPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFnLambdaTokenPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFn" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", - { - "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - }, - "__Stage__": "*" - } - ] - } - } - }, "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/cognito": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - } - }, + "/any/cognito": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "NONE": [] } - ] - } - }, - "/any/cognito": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/cognito": { + "get": { "responses": {}, "security": [ { "NONE": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyCognitoAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "cognito_user_pools", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "cognito_user_pools", "providerARNs": [ { "Fn::GetAtt": [ @@ -313,33 +58,36 @@ "Arn" ] } - ] - } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiWithCognitoAuthDeployment137d859db2": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { "Description": "RestApi deployment id: 137d859db29250f90c64fe19daa84543603d48ad", "RestApiId": { "Ref": "MyApiWithCognitoAuth" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiWithCognitoAuthDeployment137d859db2" @@ -348,63 +96,175 @@ "Ref": "MyApiWithCognitoAuth" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiWithLambdaTokenAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyApiWithLambdaRequestAuth": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/lambda-token": { + "/lambda-request": { "get": { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "passthroughBehavior": "when_no_match", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } + } + } + } + }, + "schemes": [ + "https" + ], + "securityDefinitions": { + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] }, + "identitySource": "method.request.header.Authorization1", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": 2.0 + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaRequestAuthDeploymentd295fdcc4d": { + "Properties": { + "Description": "RestApi deployment id: d295fdcc4db4c5e43af22589d4031c48b792615e", + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaRequestAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaRequestAuthDeploymentd295fdcc4d" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiWithLambdaTokenAuth": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any/lambda-token": { + "x-amazon-apigateway-any-method": { "responses": {}, "security": [ { "NONE": [] } - ] - } - }, - "/any/lambda-token": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" } - }, + } + } + }, + "/lambda-token": { + "get": { "responses": {}, "security": [ { "NONE": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" + } + } } } }, "securityDefinitions": { "MyLambdaTokenAuth": { - "type": "apiKey", - "name": "Authorization", "in": "header", - "x-amazon-apigateway-authtype": "custom", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", "authorizerUri": { "Fn::Sub": [ "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -417,180 +277,320 @@ } } ] - } + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithLambdaTokenAuthDeployment950b8f93fb": { + "Properties": { + "Description": "RestApi deployment id: 950b8f93fb50121b8dbc1c4cccd69cd65db388ff", + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiWithLambdaTokenAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithLambdaTokenAuthDeployment950b8f93fb" + }, + "RestApiId": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiWithLambdaTokenAuthDeployment950b8f93fb": { - "Type": "AWS::ApiGateway::Deployment", + "MyFn": { "Properties": { - "Description": "RestApi deployment id: 950b8f93fb50121b8dbc1c4cccd69cd65db388ff", - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "StageName": "Stage" - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFnRole", + "Arn" + ] + }, + "Runtime": "nodejs8.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyApiWithLambdaTokenAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnCognitoAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaTokenAuthDeployment950b8f93fb" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaTokenAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/cognito", + { + "__ApiId__": { + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaTokenAuthMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnCognitoPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/cognito", { "__ApiId__": { - "Ref": "MyApiWithLambdaTokenAuth" - } + "Ref": "MyApiWithCognitoAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuth": { - "Type": "AWS::ApiGateway::RestApi", + "MyFnLambdaRequestAnyMethodPermissionProd": { "Properties": { - "Body": { - "swagger": 2.0, - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "schemes": [ - "https" - ], - "paths": { - "/lambda-request": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFn.Arn}/invocations" - }, - "passthroughBehavior": "when_no_match" - }, - "responses": {}, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ] - } - } - }, - "securityDefinitions": { - "MyLambdaRequestAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authtype": "custom", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "identitySource": "method.request.header.Authorization1" - } - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthDeploymentd295fdcc4d": { - "Type": "AWS::ApiGateway::Deployment", + "MyFnLambdaRequestPermissionProd": { "Properties": { - "Description": "RestApi deployment id: d295fdcc4db4c5e43af22589d4031c48b792615e", - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-request", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaRequestAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFnLambdaTokenAnyMethodPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiWithLambdaRequestAuthDeploymentd295fdcc4d" - }, - "RestApiId": { - "Ref": "MyApiWithLambdaRequestAuth" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFn" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/lambda-token", + { + "__ApiId__": { + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiWithLambdaRequestAuthMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFnLambdaTokenPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] + "Ref": "MyFn" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/lambda-token", { "__ApiId__": { - "Ref": "MyApiWithLambdaRequestAuth" - } + "Ref": "MyApiWithLambdaTokenAuth" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans.json b/tests/translator/output/aws-us-gov/api_with_usageplans.json index 689e93aade..e054070138 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans.json @@ -1,195 +1,438 @@ { + "Outputs": { + "ApiKey": { + "Description": "Api Key", + "Value": { + "Ref": "ServerlessApiKey" + } + }, + "ApiOneUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "ApiThreeUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "ApiTwoUrl": { + "Description": "API endpoint URL for Prod environment", + "Value": { + "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + } + }, + "UsagePlan": { + "Description": "Usage Plan physical Id", + "Value": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "UsagePlanKey": { + "Description": "Usage Plan Key", + "Value": { + "Ref": "MyApiTwoUsagePlanKey" + } + } + }, "Resources": { - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", + "MyApiOne": { "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/any/path/one": { + "x-amazon-apigateway-any-method": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + }, + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyApiOneDeployment9f1f899b82": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "Description": "RestApi deployment id: 9f1f899b827f502a0c49212b7f2368322724360b", + "RestApiId": { + "Ref": "MyApiOne" }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyFunctionOneApiKeyAnyMethodPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiOneProdStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" + "DeploymentId": { + "Ref": "MyApiOneDeployment9f1f899b82" }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiThree": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/three": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyApiThreeDeployment5206882d23": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" + "Description": "RestApi deployment id: 5206882d23d2cf7913f0fffea98644f959b433f2", + "RestApiId": { + "Ref": "MyApiThree" }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiThreeDeployment5206882d23" + }, + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", + "MyApiTwoApiKey": { + "DependsOn": [ + "MyApiTwoUsagePlan" + ], "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": { + "Ref": "MyApiTwoProdStage" + } + } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" + }, + "MyApiTwoDeployment0e45b81469": { + "Properties": { + "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", + "RestApiId": { + "Ref": "MyApiTwo" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyFunctionTwoRole", - "Arn" - ] + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiTwoProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeployment0e45b81469" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwoUsagePlan": { + "DependsOn": [ + "MyApiTwo" + ], + "Properties": { + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiTwo" + }, + "Stage": { + "Ref": "MyApiTwoProdStage" + } + } + ], + "Description": "Description for usage plan", + "Quota": { + "Limit": 10, + "Offset": 10, + "Period": "MONTH" }, - "Runtime": "nodejs12.x", "Tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "Key": "key1", + "Value": "value1" + }, + { + "Key": "key2", + "Value": "value2" } - ] - } + ], + "Throttle": { + "BurstLimit": 1000, + "RateLimit": 1000 + }, + "UsagePlanName": "SomeRandomName" + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyApiTwoUsagePlanKey": { + "DependsOn": [ + "MyApiTwoApiKey" + ], "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "KeyId": { + "Ref": "MyApiTwoApiKey" + }, + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "MyApiTwoUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" + }, + "MyFunctionOne": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionTwoImplicitApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionOneApiKeyAnyMethodPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionTwo" + "Ref": "MyFunctionOne" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/event", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/any/path/one", { "__ApiId__": { - "Ref": "ServerlessRestApi" + "Ref": "MyApiOne" }, "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionOneApiKeyPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionTwo" + "Ref": "MyFunctionOne" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", { "__ApiId__": { - "Ref": "MyApiTwo" + "Ref": "MyApiOne" }, "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionThree": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -208,13 +451,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionThreeApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionThree" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + { + "__ApiId__": { + "Ref": "MyApiThree" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionThreeRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -227,7 +490,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -238,331 +502,201 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionThreeApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionTwo": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionTwoRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionTwoApiKeyPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunctionThree" + "Ref": "MyFunctionTwo" }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { "__ApiId__": { - "Ref": "MyApiThree" + "Ref": "MyApiTwo" }, "__Stage__": "*" } ] } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - }, - "/any/path/one": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiOneDeployment9f1f899b82": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 9f1f899b827f502a0c49212b7f2368322724360b", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeployment9f1f899b82" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiTwoDeployment0e45b81469": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionTwoImplicitApiEventPermissionProd": { "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment0e45b81469" - }, - "RestApiId": { - "Ref": "MyApiTwo" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" }, - "StageName": "Prod" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/event", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiTwoUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", - "DependsOn": [ - "MyApiTwo" - ], + "MyFunctionTwoRole": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiTwo" - }, - "Stage": { - "Ref": "MyApiTwoProdStage" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - } - ], - "Description": "Description for usage plan", - "Quota": { - "Limit": 10, - "Offset": 10, - "Period": "MONTH" + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Key": "key1", - "Value": "value1" - }, - { - "Key": "key2", - "Value": "value2" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Throttle": { - "BurstLimit": 1000, - "RateLimit": 1000 - }, - "UsagePlanName": "SomeRandomName" - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiTwoApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "ServerlessApiKey": { "DependsOn": [ - "MyApiTwoUsagePlan" + "ServerlessUsagePlan" ], "Properties": { "Enabled": true, "StageKeys": [ { "RestApiId": { - "Ref": "MyApiTwo" + "Ref": "MyApiThree" }, "StageName": { - "Ref": "MyApiTwoProdStage" + "Ref": "MyApiThreeProdStage" + } + }, + { + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": { + "Ref": "ServerlessRestApiProdStage" } } ] - } - }, - "MyApiTwoUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "DependsOn": [ - "MyApiTwoApiKey" - ], - "Properties": { - "KeyId": { - "Ref": "MyApiTwoApiKey" - }, - "KeyType": "API_KEY", - "UsagePlanId": { - "Ref": "MyApiTwoUsagePlan" - } - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiThree": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/path/three": { + "/path/event": { "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" - } - }, "responses": {}, "security": [ { "api_key": [] } - ] + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } } } }, "securityDefinitions": { "api_key": { - "type": "apiKey", + "in": "header", "name": "x-api-key", - "in": "header" + "type": "apiKey" } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiThreeDeployment5206882d23": { - "Type": "AWS::ApiGateway::Deployment", + "ServerlessRestApiDeploymentd197b03bdf": { "Properties": { - "Description": "RestApi deployment id: 5206882d23d2cf7913f0fffea98644f959b433f2", + "Description": "RestApi deployment id: d197b03bdfab8dddfb221e8c7f1becff9a9b1d9d", "RestApiId": { - "Ref": "MyApiThree" + "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ServerlessRestApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiThreeDeployment5206882d23" + "Ref": "ServerlessRestApiDeploymentd197b03bdf" }, "RestApiId": { - "Ref": "MyApiThree" + "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", "DependsOn": [ "MyApiThree", "ServerlessRestApi" @@ -586,37 +720,10 @@ } } ] - } - }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "DependsOn": [ - "ServerlessUsagePlan" - ], - "Properties": { - "Enabled": true, - "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": { - "Ref": "MyApiThreeProdStage" - } - }, - { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": { - "Ref": "ServerlessRestApiProdStage" - } - } - ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "DependsOn": [ "ServerlessApiKey" ], @@ -628,115 +735,8 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/event": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "ServerlessRestApiDeploymentd197b03bdf": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: d197b03bdfab8dddfb221e8c7f1becff9a9b1d9d", - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Stage" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentd197b03bdf" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - } - }, - "Outputs": { - "ApiOneUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "ApiTwoUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "ApiThreeUrl": { - "Description": "API endpoint URL for Prod environment", - "Value": { - "Fn::Sub": "https://${MyApiThree}.execute-api.${AWS::Region}.amazonaws.com/Prod/" - } - }, - "UsagePlan": { - "Description": "Usage Plan physical Id", - "Value": { - "Ref": "MyApiTwoUsagePlan" - } - }, - "UsagePlanKey": { - "Description": "Usage Plan Key", - "Value": { - "Ref": "MyApiTwoUsagePlanKey" - } - }, - "ApiKey": { - "Description": "Api Key", - "Value": { - "Ref": "ServerlessApiKey" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans_intrinsics.json b/tests/translator/output/aws-us-gov/api_with_usageplans_intrinsics.json index 0a9355d91a..998d6746bf 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans_intrinsics.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans_intrinsics.json @@ -1,26 +1,26 @@ { + "Conditions": { + "C1": { + "Fn::Equals": [ + true, + true + ] + } + }, "Outputs": { - "ApiTwoUrl": { + "ApiOneUrl": { "Description": "API endpoint URL for Prod environment", "Value": { - "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } }, - "ApiOneUrl": { + "ApiTwoUrl": { "Description": "API endpoint URL for Prod environment", "Value": { - "Fn::Sub": "https://${MyApiOne}.execute-api.${AWS::Region}.amazonaws.com/Prod/" + "Fn::Sub": "https://${MyApiTwo}.execute-api.${AWS::Region}.amazonaws.com/Prod/" } } }, - "Conditions": { - "C1": { - "Fn::Equals": [ - true, - true - ] - } - }, "Parameters": { "UsagePlanType": { "Default": "PER_API", @@ -28,32 +28,105 @@ } }, "Resources": { - "MyApiTwoUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "MyApiOne": { + "Condition": "C1", "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "MyApiTwoApiKey" + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + } }, - "UsagePlanId": { - "Ref": "MyApiTwoUsagePlan" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiOneApiKey": { + "Condition": "C1", "DependsOn": [ - "MyApiTwoApiKey" - ] + "MyApiOneUsagePlan" + ], + "Properties": { + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": { + "Ref": "MyApiOneProdStage" + } + } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiTwoDeployment802c3b471d": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiOneDeployment8b73115419": { + "Condition": "C1", "Properties": { + "Description": "RestApi deployment id: 8b731154198483502cc4b2bff739c404e88bfe41", "RestApiId": { - "Ref": "MyApiTwo" + "Ref": "MyApiOne" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeployment8b73115419" }, - "Description": "RestApi deployment id: 802c3b471de66f79d6d2cac656e6c9319fa0ba51" - } + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, "MyApiOneUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "Condition": "C1", + "DependsOn": [ + "MyApiOne" + ], "Properties": { "ApiStages": [ { @@ -66,177 +139,226 @@ } ] }, + "Type": "AWS::ApiGateway::UsagePlan" + }, + "MyApiOneUsagePlanKey": { + "Condition": "C1", "DependsOn": [ - "MyApiOne" + "MyApiOneApiKey" ], - "Condition": "C1" + "Properties": { + "KeyId": { + "Ref": "MyApiOneApiKey" + }, + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "MyApiOneUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" }, - "MyApiOneDeployment8b73115419": { - "Type": "AWS::ApiGateway::Deployment", + "MyApiTwo": { "Properties": { - "RestApiId": { - "Ref": "MyApiOne" + "Body": { + "components": { + "securitySchemes": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.0", + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + } }, - "Description": "RestApi deployment id: 8b731154198483502cc4b2bff739c404e88bfe41" + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } }, - "Condition": "C1" + "Type": "AWS::ApiGateway::RestApi" }, - "MyApiTwoUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiTwoApiKey": { + "DependsOn": [ + "MyApiTwoUsagePlan" + ], "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } } ] }, - "DependsOn": [ - "MyApiTwo" - ] + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiTwoDeployment802c3b471d": { "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment802c3b471d" - }, + "Description": "RestApi deployment id: 802c3b471de66f79d6d2cac656e6c9319fa0ba51", "RestApiId": { "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } + } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyApiTwoProdStage": { "Properties": { "DeploymentId": { - "Ref": "MyApiOneDeployment8b73115419" + "Ref": "MyApiTwoDeployment802c3b471d" }, "RestApiId": { - "Ref": "MyApiOne" + "Ref": "MyApiTwo" }, "StageName": "Prod" }, - "Condition": "C1" + "Type": "AWS::ApiGateway::Stage" }, - "MyApiOneApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyApiTwoUsagePlan": { + "DependsOn": [ + "MyApiTwo" + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { - "Ref": "MyApiOne" + "ApiId": { + "Ref": "MyApiTwo" }, - "StageName": { - "Ref": "MyApiOneProdStage" + "Stage": { + "Ref": "MyApiTwoProdStage" } } ] }, + "Type": "AWS::ApiGateway::UsagePlan" + }, + "MyApiTwoUsagePlanKey": { "DependsOn": [ - "MyApiOneUsagePlan" + "MyApiTwoApiKey" ], - "Condition": "C1" - }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyApiOneUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "Properties": { - "KeyType": "API_KEY", "KeyId": { - "Ref": "MyApiOneApiKey" + "Ref": "MyApiTwoApiKey" }, + "KeyType": "API_KEY", "UsagePlanId": { - "Ref": "MyApiOneUsagePlan" + "Ref": "MyApiTwoUsagePlan" } }, - "DependsOn": [ - "MyApiOneApiKey" - ], - "Condition": "C1" + "Type": "AWS::ApiGateway::UsagePlanKey" }, - "MyApiTwoApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "MyFunctionOne": { "Properties": { - "Enabled": true, - "StageKeys": [ + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": { - "Ref": "MyApiTwoProdStage" - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyApiTwoUsagePlan" - ] + "Type": "AWS::Lambda::Function" }, "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionOne" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiOne" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionTwoRole", @@ -246,41 +368,37 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionTwo" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiTwo" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -293,138 +411,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0.0", - "components": { - "securitySchemes": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } }, - "Condition": "C1" - }, - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_three.json b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_three.json index 26b69c39b7..fad903caeb 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_three.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_three.json @@ -14,8 +14,229 @@ } }, "Resources": { + "MyApiOne": { + "Condition": "C1", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Delete" + }, + "MyApiOneDeploymentdccbc5fda1": { + "Condition": "C1", + "Properties": { + "Description": "RestApi deployment id: dccbc5fda163e1abe712073ffacdcc47776a5a09", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Delete" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeploymentdccbc5fda1" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Delete" + }, + "MyApiThree": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/three": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiThreeDeployment5206882d23": { + "Properties": { + "Description": "RestApi deployment id: 5206882d23d2cf7913f0fffea98644f959b433f2", + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiThreeProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiThreeDeployment5206882d23" + }, + "RestApiId": { + "Ref": "MyApiThree" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Condition": "C2", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Snapshot" + }, + "MyApiTwoDeployment0e45b81469": { + "Condition": "C2", + "Properties": { + "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Snapshot" + }, + "MyApiTwoProdStage": { + "Condition": "C2", + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeployment0e45b81469" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Snapshot" + }, "MyFunctionOne": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -34,13 +255,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -53,7 +294,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -64,31 +306,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", + "MyFunctionThree": { "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -96,7 +317,7 @@ "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionTwoRole", + "MyFunctionThreeRole", "Arn" ] }, @@ -107,13 +328,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionThreeApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionThree" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", + { + "__ApiId__": { + "Ref": "MyApiThree" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionThreeRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -126,7 +367,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -137,31 +379,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", - { - "__ApiId__": { - "Ref": "MyApiTwo" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyFunctionThree": { - "Type": "AWS::Lambda::Function", + "MyFunctionTwo": { "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -169,7 +390,7 @@ "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionThreeRole", + "MyFunctionTwoRole", "Arn" ] }, @@ -180,13 +401,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionThreeRole": { - "Type": "AWS::IAM::Role", + "MyFunctionTwoApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + { + "__ApiId__": { + "Ref": "MyApiTwo" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionTwoRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -199,7 +440,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -210,184 +452,86 @@ "Value": "SAM" } ] - } - }, - "MyFunctionThreeApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionThree" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/three", - { - "__ApiId__": { - "Ref": "MyApiThree" - }, - "__Stage__": "*" - } - ] - } - } - }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiOneDeploymentdccbc5fda1": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "Description": "RestApi deployment id: dccbc5fda163e1abe712073ffacdcc47776a5a09", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C1", - "UpdateReplacePolicy": "Delete", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeploymentdccbc5fda1" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "ServerlessApiKey": { "DependsOn": [ - "MyApiOne", - "MyApiTwo", - "MyApiThree" + "ServerlessUsagePlan" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiThree" }, - "Stage": { + "StageName": { "Ref": "MyApiThreeProdStage" } } ] - } - }, - "ServerlessApiKey": { + }, "Type": "AWS::ApiGateway::ApiKey", + "UpdateReplacePolicy": "Snapshot" + }, + "ServerlessUsagePlan": { "DependsOn": [ - "ServerlessUsagePlan" + "MyApiOne", + "MyApiTwo", + "MyApiThree" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiOne" }, - "StageName": { + "Stage": { "Ref": "MyApiOneProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiThree" }, - "StageName": { + "Stage": { "Ref": "MyApiThreeProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan", + "UpdateReplacePolicy": "Snapshot" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", "DependsOn": [ "ServerlessApiKey" ], - "UpdateReplacePolicy": "Snapshot", "Properties": { "KeyId": { "Ref": "ServerlessApiKey" @@ -396,153 +540,9 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiTwoDeployment0e45b81469": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C2", - "UpdateReplacePolicy": "Snapshot", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment0e45b81469" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } - }, - "MyApiThree": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/three": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionThree.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiThreeDeployment5206882d23": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 5206882d23d2cf7913f0fffea98644f959b433f2", - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": "Stage" - } - }, - "MyApiThreeProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiThreeDeployment5206882d23" - }, - "RestApiId": { - "Ref": "MyApiThree" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey", + "UpdateReplacePolicy": "Snapshot" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_two.json b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_two.json index 346ef6a12d..bdb73f8573 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_two.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_attributes_two.json @@ -24,8 +24,159 @@ } }, "Resources": { + "MyApiOne": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiOneDeploymentdccbc5fda1": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "Description": "RestApi deployment id: dccbc5fda163e1abe712073ffacdcc47776a5a09", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Condition": "C1", + "DeletionPolicy": "Delete", + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeploymentdccbc5fda1" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiTwoDeployment0e45b81469": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiTwoProdStage": { + "Condition": "C2", + "DeletionPolicy": "Retain", + "Properties": { + "DeploymentId": { + "Ref": "MyApiTwoDeployment0e45b81469" + }, + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunctionOne": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -44,13 +195,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -63,7 +234,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -74,31 +246,10 @@ "Value": "SAM" } ] - } - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__ApiId__": { - "Ref": "MyApiOne" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" @@ -117,13 +268,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionTwoApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionTwo" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", + { + "__ApiId__": { + "Ref": "MyApiTwo" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -136,7 +307,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -147,170 +319,73 @@ "Value": "SAM" } ] - } - }, - "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "MyFunctionTwo" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", - { - "__ApiId__": { - "Ref": "MyApiTwo" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role" }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", - "DeletionPolicy": "Delete", - "Condition": "C1", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiOneDeploymentdccbc5fda1": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C1", - "DeletionPolicy": "Delete", - "Properties": { - "Description": "RestApi deployment id: dccbc5fda163e1abe712073ffacdcc47776a5a09", - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Stage" - } - }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C1", - "DeletionPolicy": "Delete", - "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeploymentdccbc5fda1" - }, - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": "Prod" - } - }, - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", - "DependsOn": [ - "MyApiOne", - "MyApiTwo" - ], + "ServerlessApiKey": { "Condition": "SharedUsagePlanCondition", "DeletionPolicy": "Retain", + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "ApiStages": [ + "Enabled": true, + "StageKeys": [ { - "ApiId": { + "RestApiId": { "Ref": "MyApiOne" }, - "Stage": { + "StageName": { "Ref": "MyApiOneProdStage" } }, { - "ApiId": { + "RestApiId": { "Ref": "MyApiTwo" }, - "Stage": { + "StageName": { "Ref": "MyApiTwoProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "DependsOn": [ - "ServerlessUsagePlan" - ], + "ServerlessUsagePlan": { "Condition": "SharedUsagePlanCondition", "DeletionPolicy": "Retain", + "DependsOn": [ + "MyApiOne", + "MyApiTwo" + ], "Properties": { - "Enabled": true, - "StageKeys": [ + "ApiStages": [ { - "RestApiId": { + "ApiId": { "Ref": "MyApiOne" }, - "StageName": { + "Stage": { "Ref": "MyApiOneProdStage" } }, { - "RestApiId": { + "ApiId": { "Ref": "MyApiTwo" }, - "StageName": { + "Stage": { "Ref": "MyApiTwoProdStage" } } ] - } + }, + "Type": "AWS::ApiGateway::UsagePlan" }, "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", + "Condition": "SharedUsagePlanCondition", + "DeletionPolicy": "Retain", "DependsOn": [ "ServerlessApiKey" ], - "Condition": "SharedUsagePlanCondition", - "DeletionPolicy": "Retain", "Properties": { "KeyId": { "Ref": "ServerlessApiKey" @@ -319,83 +394,8 @@ "UsagePlanId": { "Ref": "ServerlessUsagePlan" } - } - }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", - "DeletionPolicy": "Retain", - "Condition": "C2", - "Properties": { - "Body": { - "swagger": "2.0", - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "type": "aws_proxy", - "httpMethod": "POST", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "responses": {}, - "security": [ - { - "api_key": [] - } - ] - } - } - }, - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } - }, - "MyApiTwoDeployment0e45b81469": { - "Type": "AWS::ApiGateway::Deployment", - "Condition": "C2", - "DeletionPolicy": "Retain", - "Properties": { - "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Stage" - } - }, - "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Condition": "C2", - "DeletionPolicy": "Retain", - "Properties": { - "DeploymentId": { - "Ref": "MyApiTwoDeployment0e45b81469" - }, - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_1.json b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_1.json index b17f3638b0..ba13b5b974 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_1.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_1.json @@ -1,74 +1,134 @@ { "Resources": { - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiOne": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiOne" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "Stage": { - "Ref": "MyApiOneProdStage" + "version": "1.0" + }, + "paths": { + "/path/one": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" + } + } + } } }, - { - "ApiId": { - "Ref": "MyApiTwo" - }, - "Stage": { - "Ref": "MyApiTwoProdStage" + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - ] + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } }, - "DependsOn": [ - "MyApiOne", - "MyApiTwo" - ] + "Type": "AWS::ApiGateway::RestApi" }, - "MyFunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyApiOneDeploymentdccbc5fda1": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Description": "RestApi deployment id: dccbc5fda163e1abe712073ffacdcc47776a5a09", + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiOneProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiOneDeploymentdccbc5fda1" + }, + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyApiTwo": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/path/two": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" + } + } } } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "MyApiTwoDeployment0e45b81469": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", "RestApiId": { "Ref": "MyApiTwo" }, - "Description": "RestApi deployment id: 0e45b814691166a59217a088512ee30710a12369", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "MyApiTwoProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "MyApiTwoDeployment0e45b81469" @@ -77,25 +137,55 @@ "Ref": "MyApiTwo" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "MyApiOneProdStage": { - "Type": "AWS::ApiGateway::Stage", + "MyFunctionOne": { "Properties": { - "DeploymentId": { - "Ref": "MyApiOneDeploymentdccbc5fda1" + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "RestApiId": { - "Ref": "MyApiOne" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionOneRole", + "Arn" + ] }, - "StageName": "Prod" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyFunctionTwoRole": { - "Type": "AWS::IAM::Role", + "MyFunctionOneApiKeyPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunctionOne" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", + { + "__ApiId__": { + "Ref": "MyApiOne" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionOneRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -108,89 +198,27 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", - "Properties": { - "Enabled": true, - "StageKeys": [ - { - "RestApiId": { - "Ref": "MyApiOne" - }, - "StageName": { - "Ref": "MyApiOneProdStage" - } - }, - { - "RestApiId": { - "Ref": "MyApiTwo" - }, - "StageName": { - "Ref": "MyApiTwoProdStage" - } - } - ] - }, - "DependsOn": [ - "ServerlessUsagePlan" - ] - }, - "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "ServerlessApiKey" - }, - "UsagePlanId": { - "Ref": "ServerlessUsagePlan" - } }, - "DependsOn": [ - "ServerlessApiKey" - ] - }, - "MyFunctionOneApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunctionOne" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/one", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApiOne" - } - } - ] - } - } + "Type": "AWS::IAM::Role" }, "MyFunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunctionTwoRole", @@ -200,160 +228,132 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionTwoApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionTwo" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/two", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiTwo" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyApiOneDeploymentdccbc5fda1": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionTwoRole": { "Properties": { - "RestApiId": { - "Ref": "MyApiOne" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: dccbc5fda163e1abe712073ffacdcc47776a5a09", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyApiTwo": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessApiKey": { + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/two": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionTwo.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } + "Enabled": true, + "StageKeys": [ + { + "RestApiId": { + "Ref": "MyApiOne" + }, + "StageName": { + "Ref": "MyApiOneProdStage" } }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + { + "RestApiId": { + "Ref": "MyApiTwo" + }, + "StageName": { + "Ref": "MyApiTwoProdStage" } } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + ] + }, + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiOne": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessUsagePlan": { + "DependsOn": [ + "MyApiOne", + "MyApiTwo" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/one": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionOne.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiOne" + }, + "Stage": { + "Ref": "MyApiOneProdStage" } }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + { + "ApiId": { + "Ref": "MyApiTwo" + }, + "Stage": { + "Ref": "MyApiTwoProdStage" } } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + ] + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyFunctionOne": { - "Type": "AWS::Lambda::Function", + "ServerlessUsagePlanKey": { + "DependsOn": [ + "ServerlessApiKey" + ], "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionOneRole", - "Arn" - ] + "KeyId": { + "Ref": "ServerlessApiKey" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "ServerlessUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_2.json b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_2.json index 441f68ed1c..a5fd747489 100644 --- a/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_2.json +++ b/tests/translator/output/aws-us-gov/api_with_usageplans_shared_no_side_effect_2.json @@ -1,64 +1,121 @@ { "Resources": { - "ServerlessUsagePlan": { - "Type": "AWS::ApiGateway::UsagePlan", + "MyApiFour": { "Properties": { - "ApiStages": [ - { - "ApiId": { - "Ref": "MyApiFour" + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" }, - "Stage": { - "Ref": "MyApiFourProdStage" + "version": "1.0" + }, + "paths": { + "/path/four": { + "get": { + "responses": {}, + "security": [ + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionFour.Arn}/invocations" + } + } + } + } + }, + "securityDefinitions": { + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiFourDeploymentb6dc37f7cc": { + "Properties": { + "Description": "RestApi deployment id: b6dc37f7cc5eef500a43cb766cd9336e4956b0d2", + "RestApiId": { + "Ref": "MyApiFour" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiFourProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiFourDeploymentb6dc37f7cc" + }, + "RestApiId": { + "Ref": "MyApiFour" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunctionFour": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionFourRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyApiFour" - ] + "Type": "AWS::Lambda::Function" }, "MyFunctionFourApiKeyPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunctionFour" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/path/four", { - "__Stage__": "*", "__ApiId__": { "Ref": "MyApiFour" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessUsagePlanKey": { - "Type": "AWS::ApiGateway::UsagePlanKey", - "Properties": { - "KeyType": "API_KEY", - "KeyId": { - "Ref": "ServerlessApiKey" - }, - "UsagePlanId": { - "Ref": "ServerlessUsagePlan" - } }, - "DependsOn": [ - "ServerlessApiKey" - ] + "Type": "AWS::Lambda::Permission" }, "MyFunctionFourRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -71,43 +128,25 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionFour": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionFourRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessApiKey": { - "Type": "AWS::ApiGateway::ApiKey", + "DependsOn": [ + "ServerlessUsagePlan" + ], "Properties": { "Enabled": true, "StageKeys": [ @@ -121,79 +160,40 @@ } ] }, - "DependsOn": [ - "ServerlessUsagePlan" - ] + "Type": "AWS::ApiGateway::ApiKey" }, - "MyApiFour": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessUsagePlan": { + "DependsOn": [ + "MyApiFour" + ], "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/path/four": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunctionFour.Arn}/invocations" - } - }, - "security": [ - { - "api_key": [] - } - ], - "responses": {} - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "ApiStages": [ + { + "ApiId": { + "Ref": "MyApiFour" + }, + "Stage": { + "Ref": "MyApiFourProdStage" } } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, - "MyApiFourDeploymentb6dc37f7cc": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiFour" - }, - "Description": "RestApi deployment id: b6dc37f7cc5eef500a43cb766cd9336e4956b0d2", - "StageName": "Stage" - } + ] + }, + "Type": "AWS::ApiGateway::UsagePlan" }, - "MyApiFourProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ServerlessUsagePlanKey": { + "DependsOn": [ + "ServerlessApiKey" + ], "Properties": { - "DeploymentId": { - "Ref": "MyApiFourDeploymentb6dc37f7cc" - }, - "RestApiId": { - "Ref": "MyApiFour" + "KeyId": { + "Ref": "ServerlessApiKey" }, - "StageName": "Prod" - } + "KeyType": "API_KEY", + "UsagePlanId": { + "Ref": "ServerlessUsagePlan" + } + }, + "Type": "AWS::ApiGateway::UsagePlanKey" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/api_with_xray_tracing.json b/tests/translator/output/aws-us-gov/api_with_xray_tracing.json index f8b546a91a..1202b5a511 100644 --- a/tests/translator/output/aws-us-gov/api_with_xray_tracing.json +++ b/tests/translator/output/aws-us-gov/api_with_xray_tracing.json @@ -1,37 +1,33 @@ { "Resources": { - "HtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "HtmlApi": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "HtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "HtmlApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "HtmlApiDeploymentf117c932f7" @@ -41,76 +37,80 @@ }, "StageName": "Prod", "TracingEnabled": true - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "HtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "HtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "HtmlFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "HtmlApi" + "__ApiId__": "HtmlApi", + "__Stage__": "*" } ] } - } - }, - "HtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "HtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "HtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "HtmlFunction": { - "Type": "AWS::Lambda::Function", + "HtmlFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "HtmlFunctionRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/application_preparing_state.json b/tests/translator/output/aws-us-gov/application_preparing_state.json index 92fe7cc8d7..9129453a05 100644 --- a/tests/translator/output/aws-us-gov/application_preparing_state.json +++ b/tests/translator/output/aws-us-gov/application_preparing_state.json @@ -1,24 +1,24 @@ { "Resources": { "PreparingApplication": { - "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" }, { - "Value": "preparing", - "Key": "serverlessrepo:applicationId" + "Key": "serverlessrepo:applicationId", + "Value": "preparing" }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" } } } diff --git a/tests/translator/output/aws-us-gov/application_with_intrinsics.json b/tests/translator/output/aws-us-gov/application_with_intrinsics.json index b21b0c3ea8..f329e9bbba 100644 --- a/tests/translator/output/aws-us-gov/application_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/application_with_intrinsics.json @@ -1,76 +1,76 @@ { - "Parameters": { - "ApplicationIdParam": { - "Default": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Type": "String" - }, - "VersionParam": { - "Default": "1.0.0", - "Type": "String" - } - }, "Mappings": { "ApplicationLocations": { + "ap-southeast-1": { + "ApplicationId": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world", + "Version": "1.0.1" + }, "cn-north-1": { - "Version": "1.0.2", - "ApplicationId": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world" - }, + "ApplicationId": "arn:aws-cn:serverlessrepo:cn-north-1:123456789012:applications/hello-world", + "Version": "1.0.2" + }, "us-gov-west-1": { - "Version": "1.0.3", - "ApplicationId": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world" - }, - "ap-southeast-1": { - "Version": "1.0.1", - "ApplicationId": "arn:aws:serverlessrepo:ap-southeast-1:123456789012:applications/hello-world" + "ApplicationId": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world", + "Version": "1.0.3" } } - }, + }, + "Parameters": { + "ApplicationIdParam": { + "Default": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", + "Type": "String" + }, + "VersionParam": { + "Default": "1.0.0", + "Type": "String" + } + }, "Resources": { "ApplicationFindInMap": { - "Type": "AWS::CloudFormation::Stack", "Properties": { "NotificationARNs": [ { "Ref": "Sns" } - ], - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws-gov:serverlessrepo:us-gov-west-1:123456789012:applications/hello-world" + }, { - "Value": "1.0.3", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.3" } - ] - } - }, + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, "ApplicationRefParameter": { - "Type": "AWS::CloudFormation::Stack", "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "1.0.0", - "Key": "serverlessrepo:semanticVersion" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.0" } - ] - } - }, + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, "Sns": { "Type": "AWS::SNS::Topic" } diff --git a/tests/translator/output/aws-us-gov/basic_application.json b/tests/translator/output/aws-us-gov/basic_application.json index 058e8037e5..96a827f8e5 100644 --- a/tests/translator/output/aws-us-gov/basic_application.json +++ b/tests/translator/output/aws-us-gov/basic_application.json @@ -2,99 +2,99 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Resources": { - "NormalApplication": { - "Type": "AWS::CloudFormation::Stack", + "ApplicationWithCondition": { + "Condition": "TestCondition", "Properties": { - "NotificationARNs": [ - "arn:aws:sns:us-east-1:123456789012:sns-arn" - ], - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", - "TimeoutInMinutes": 15, - "Parameters": { - "IdentityNameParameter": "IdentityName" - }, "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "TagValue", - "Key": "TagName" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, - "BasicApplication": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "ApplicationWithLocationUrl": { "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "TagName2", + "Value": "TagValue2" } - ] - } - }, - "ApplicationWithLocationUrl": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "BasicApplication": { "Properties": { - "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "TagValue2", - "Key": "TagName2" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, - "ApplicationWithCondition": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "NormalApplication": { "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "NotificationARNs": [ + "arn:aws:sns:us-east-1:123456789012:sns-arn" + ], + "Parameters": { + "IdentityNameParameter": "IdentityName" + }, "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "TagName", + "Value": "TagValue" } - ] - }, - "Condition": "TestCondition" + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TimeoutInMinutes": 15 + }, + "Type": "AWS::CloudFormation::Stack" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/basic_function.json b/tests/translator/output/aws-us-gov/basic_function.json index ad22b6c2b2..23abc5e833 100644 --- a/tests/translator/output/aws-us-gov/basic_function.json +++ b/tests/translator/output/aws-us-gov/basic_function.json @@ -1,459 +1,459 @@ { "Parameters": { - "SomeParameter": { - "Default": "param", - "Type": "String" - }, "SomeOtherParameter": { - "Default": "otherparam", + "Default": "otherparam", + "Type": "String" + }, + "SomeParameter": { + "Default": "param", "Type": "String" } - }, + }, "Resources": { - "FunctionWithInlineCode": { - "Type": "AWS::Lambda::Function", + "CompleteFunction": { "Properties": { - "TracingConfig": { - "Mode": "Active" - }, "Code": { - "ZipFile": "hello world" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Starter Lambda Function", + "Environment": { + "Variables": { + "Name": "Value", + "Name2": "Value2" + } + }, + "FunctionName": "MyAwesomeFunction", + "Handler": "hello.handler", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", + ], + "Timeout": 60, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", + { + "Ref": "SomeParameter" + }, + { + "Ref": "SomeOtherParameter" + } + ] + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithCodeUriObject": { + "Properties": { + "Code": { + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "1" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithInlineCodeRole", + "FunctionWithCodeUriObjectRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithCodeUriObjectRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithInlineCode": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + "ZipFile": "hello world" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "FunctionWithInlineCodeRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "TracingConfig": { + "Mode": "Active" + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithInlineCodeRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithPolicies": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", + "FunctionWithPoliciesRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithPoliciesRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithPolicyDocument": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "FunctionWithPolicyDocumentRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithCodeUriObjectRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithPolicyDocumentRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Path": "/", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Policies": [ { - "PolicyName": "root", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Allow" + "Action": [ + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "ec2.amazonaws.com" - ] - } - } - ] - } - } - }, - "CompleteFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Starter Lambda Function", - "VpcConfig": { - "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08", - { - "Ref": "SomeParameter" - }, - { - "Ref": "SomeOtherParameter" - } - ], - "SecurityGroupIds": [ - "sg-edcd9784" - ] - }, + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Environment": { - "Variables": { - "Name2": "Value2", - "Name": "Value" + "Key": "lambda:createdBy", + "Value": "SAM" } - }, - "Handler": "hello.handler", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "Runtime": "python2.7", - "FunctionName": "MyAwesomeFunction" - } - }, - "FunctionWithCodeUriObject": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithRoleRef": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": "1" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithCodeUriObjectRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithTracing": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithTracingRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "TracingConfig": { + "Mode": "Active" + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithTracingRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithInlineCodeRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithTracingRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess" + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "ec2.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionWithTracing": { - "Type": "AWS::Lambda::Function", - "Properties": { - "TracingConfig": { - "Mode": "Active" - }, - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithTracingRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + ], + "Version": "2012-10-17" + }, + "Path": "/", "Policies": [ { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", "PolicyDocument": { "Statement": [ { - "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" + "Action": "*", + "Effect": "Allow", + "Resource": "*" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "root" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/basic_function_with_tags.json b/tests/translator/output/aws-us-gov/basic_function_with_tags.json index 2e9855ec6c..7826f2c8ed 100644 --- a/tests/translator/output/aws-us-gov/basic_function_with_tags.json +++ b/tests/translator/output/aws-us-gov/basic_function_with_tags.json @@ -1,5 +1,5 @@ { - "AWSTemplateFormatVersion": "2010-09-09", + "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "TagValueParam": { "Default": "Val", @@ -7,107 +7,107 @@ } }, "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", + "AlexaSkillFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" }, { - "Value": "TagValue1", - "Key": "TagKey1" + "Key": "TagKey1", + "Value": "TagValue1" }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "TagValue1", - "Key": "TagKey1" - }, + "Key": "TagKey1", + "Value": "TagValue1" + }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/basic_function_withimageuri.json b/tests/translator/output/aws-us-gov/basic_function_withimageuri.json index bb91395e60..37ed8e7fcc 100644 --- a/tests/translator/output/aws-us-gov/basic_function_withimageuri.json +++ b/tests/translator/output/aws-us-gov/basic_function_withimageuri.json @@ -1,54 +1,61 @@ { "Parameters": { - "SomeParameter": { - "Type": "String", - "Default": "param" - }, "SomeOtherParameter": { - "Type": "String", - "Default": "otherparam" + "Default": "otherparam", + "Type": "String" + }, + "SomeParameter": { + "Default": "param", + "Type": "String" } }, "Resources": { - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "CompleteImageFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": { - "Service": [ - "ec2.amazonaws.com" - ] - }, - "Action": [ - "sts:AssumeRole" - ] - } - ] + "Code": { + "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, - "Path": "/", - "Policies": [ + "Description": "Starter Lambda Function", + "Environment": { + "Variables": { + "Name": "Value", + "Name2": "Value2" + } + }, + "FunctionName": "MyAwesomeFunction", + "ImageConfig": { + "Command": "/bin/sh", + "EntryPoint": "echo hello world!", + "WorkingDirectory": "/var/task" + }, + "PackageType": "Image", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Tags": [ { - "PolicyName": "root", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": "*", - "Resource": "*" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ] - } + ], + "Timeout": 60, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", + { + "Ref": "SomeParameter" + }, + { + "Ref": "SomeOtherParameter" + } + ] + } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithPolicies": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" @@ -56,7 +63,7 @@ "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "MinimalImageFunctionRole", + "FunctionWithPoliciesRole", "Arn" ] }, @@ -66,13 +73,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunctionRole": { - "Type": "AWS::IAM::Role", + "FunctionWithPoliciesRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -85,10 +91,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" ], "Tags": [ { @@ -96,10 +104,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalImageFunctionPackageTypeAndImageConfig": { - "Type": "AWS::Lambda::Function", + "FunctionWithPolicyDocument": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" @@ -107,7 +115,7 @@ "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "MinimalImageFunctionPackageTypeAndImageConfigRole", + "FunctionWithPolicyDocumentRole", "Arn" ] }, @@ -116,19 +124,13 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "ImageConfig": { - "WorkingDirectory": "/var/task", - "Command": "/bin/sh", - "EntryPoint": "echo hello world!" - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunctionPackageTypeAndImageConfigRole": { - "Type": "AWS::IAM::Role", + "FunctionWithPolicyDocumentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -141,74 +143,93 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ] + }, + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0" + } + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "CompleteImageFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithRoleRef": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, "PackageType": "Image", - "Description": "Starter Lambda Function", - "FunctionName": "MyAwesomeFunction", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "VpcConfig": { - "SecurityGroupIds": [ - "sg-edcd9784" - ], - "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08", - { - "Ref": "SomeParameter" - }, - { - "Ref": "SomeOtherParameter" - } + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" ] }, - "Environment": { - "Variables": { - "Name": "Value", - "Name2": "Value2" + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalImageFunction": { + "Properties": { + "Code": { + "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" + }, + "PackageType": "Image", + "Role": { + "Fn::GetAtt": [ + "MinimalImageFunctionRole", + "Arn" + ] }, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "ImageConfig": { - "WorkingDirectory": "/var/task", - "Command": "/bin/sh", - "EntryPoint": "echo hello world!" - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + "MinimalImageFunctionPackageTypeAndImageConfig": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, + "ImageConfig": { + "Command": "/bin/sh", + "EntryPoint": "echo hello world!", + "WorkingDirectory": "/var/task" + }, "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "MinimalImageFunctionPackageTypeAndImageConfigRole", "Arn" ] }, @@ -218,13 +239,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + "MinimalImageFunctionPackageTypeAndImageConfigRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -237,11 +257,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { @@ -249,34 +269,42 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + "MinimalImageFunctionRole": { "Properties": { - "Code": { - "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" - }, - "PackageType": "Image", - "Role": { - "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -285,59 +313,31 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "ec2.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Path": "/", "Policies": [ { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", "PolicyDocument": { "Statement": [ { - "Action": [ - "dynamodb:*" - ], + "Action": "*", "Effect": "Allow", "Resource": "*" } - ] - } - } - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" - }, - "PackageType": "Image", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" + ], + "Version": "2012-10-17" + }, + "PolicyName": "root" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/basic_layer.json b/tests/translator/output/aws-us-gov/basic_layer.json index 28754de471..94901714e4 100644 --- a/tests/translator/output/aws-us-gov/basic_layer.json +++ b/tests/translator/output/aws-us-gov/basic_layer.json @@ -2,7 +2,7 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "beta", + "beta", "beta" ] } @@ -14,94 +14,94 @@ } }, "Resources": { - "LayerWithCondition7c655e10ea": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "CompleteLayer5d71a60e81": { + "DeletionPolicy": "Retain", "Properties": { + "CompatibleRuntimes": [ + "python3.6", + "python2.7" + ], "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "LayerWithCondition" - }, - "Condition": "TestCondition" - }, - "MinimalLayer0c7f96cce7": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "Description": "Starter Lambda Layer", + "LayerName": "MyAwesomeLayer", + "LicenseInfo": "License information" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithArchitecturesab56a78493": { + "DeletionPolicy": "Retain", "Properties": { + "CompatibleArchitectures": [ + "x86_64", + "arm64" + ], "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MinimalLayer" - } - }, - "CompleteLayer5d71a60e81": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "LayerName": "LayerWithArchitectures" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithCaseInsensitiveRetentionPolicyead52a491d": { + "DeletionPolicy": "Delete", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MyAwesomeLayer", - "Description": "Starter Lambda Layer", - "LicenseInfo": "License information", - "CompatibleRuntimes": [ - "python3.6", - "python2.7" - ] - } + }, + "LayerName": "LayerWithCaseInsensitiveRetentionPolicy" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithContentUriObjectbdbf1b82ac": { - "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", + "LayerWithCondition7c655e10ea": { + "Condition": "TestCondition", + "DeletionPolicy": "Retain", "Properties": { "Content": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": "v1" - }, - "LayerName": "LayerWithContentUriObject" - } + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithCondition" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithCaseInsensitiveRetentionPolicyead52a491d": { + "LayerWithContentUriObjectbdbf1b82ac": { "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "v1" }, - "LayerName": "LayerWithCaseInsensitiveRetentionPolicy" - } + "LayerName": "LayerWithContentUriObject" + }, + "Type": "AWS::Lambda::LayerVersion" }, "LayerWithRetentionPolicyParamcc64815342": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, "LayerName": "LayerWithRetentionPolicyParam" - } - }, - "LayerWithArchitecturesab56a78493": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "MinimalLayer0c7f96cce7": { + "DeletionPolicy": "Retain", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "CompatibleArchitectures": [ - "x86_64", - "arm64" - ], - "LayerName": "LayerWithArchitectures" - } + }, + "LayerName": "MinimalLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } } diff --git a/tests/translator/output/aws-us-gov/cloudwatch_logs_with_ref.json b/tests/translator/output/aws-us-gov/cloudwatch_logs_with_ref.json index f61871da51..569264fe76 100644 --- a/tests/translator/output/aws-us-gov/cloudwatch_logs_with_ref.json +++ b/tests/translator/output/aws-us-gov/cloudwatch_logs_with_ref.json @@ -1,5 +1,6 @@ { "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Example CloudWatch Logs + Lambda", "Parameters": { "FilterPattern": { "Default": "My filter pattern", @@ -11,28 +12,7 @@ } }, "Resources": { - "TriggeredFunctionCWLogEvent": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Fn::GetAtt": [ - "TriggeredFunction", - "Arn" - ] - }, - "FilterPattern": { - "Ref": "FilterPattern" - }, - "LogGroupName": { - "Ref": "LogGroupName" - } - }, - "DependsOn": [ - "TriggeredFunctionCWLogEventPermission" - ] - }, "TriggeredFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -49,50 +29,40 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", + "TriggeredFunctionCWLogEvent": { + "DependsOn": [ + "TriggeredFunctionCWLogEventPermission" + ], "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "DestinationArn": { + "Fn::GetAtt": [ + "TriggeredFunction", + "Arn" ] + }, + "FilterPattern": { + "Ref": "FilterPattern" + }, + "LogGroupName": { + "Ref": "LogGroupName" } - } + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "TriggeredFunctionCWLogEventPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "TriggeredFunction" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -103,8 +73,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "Example CloudWatch Logs + Lambda" + } } diff --git a/tests/translator/output/aws-us-gov/cloudwatchevent.json b/tests/translator/output/aws-us-gov/cloudwatchevent.json index 3d8914b214..f35727a8d3 100644 --- a/tests/translator/output/aws-us-gov/cloudwatchevent.json +++ b/tests/translator/output/aws-us-gov/cloudwatchevent.json @@ -1,185 +1,185 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json b/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json index c8d97aea65..21302002a5 100644 --- a/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json +++ b/tests/translator/output/aws-us-gov/cloudwatchevent_intrinsics.json @@ -1,14 +1,4 @@ { - "Parameters": { - "PathA": { - "Type": "String", - "Default": "SomeInputPath" - }, - "PathB": { - "Type": "String", - "Default": "AnotherInputPath" - } - }, "Conditions": { "PathCondition": { "Fn::Equals": [ @@ -17,9 +7,18 @@ ] } }, + "Parameters": { + "PathA": { + "Default": "SomeInputPath", + "Type": "String" + }, + "PathB": { + "Default": "AnotherInputPath", + "Type": "String" + } + }, "Resources": { "LambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -39,40 +38,10 @@ "Value": "SAM" } ] - } - }, - "LambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "LambdaFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { "EventBusName": { "Fn::Join": [ @@ -125,10 +94,10 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "LambdaFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -141,7 +110,38 @@ "Arn" ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "LambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/cloudwatchlog.json b/tests/translator/output/aws-us-gov/cloudwatchlog.json index 74d47771de..7b60f3cd6d 100644 --- a/tests/translator/output/aws-us-gov/cloudwatchlog.json +++ b/tests/translator/output/aws-us-gov/cloudwatchlog.json @@ -1,23 +1,6 @@ { "Resources": { - "TriggeredFunctionCWLogEvent": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Fn::GetAtt": [ - "TriggeredFunction", - "Arn" - ] - }, - "FilterPattern": "My filter pattern", - "LogGroupName": "MyCWLogGroup" - }, - "DependsOn": [ - "TriggeredFunctionCWLogEventPermission" - ] - }, "TriggeredFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -34,50 +17,36 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", + "TriggeredFunctionCWLogEvent": { + "DependsOn": [ + "TriggeredFunctionCWLogEventPermission" + ], "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "DestinationArn": { + "Fn::GetAtt": [ + "TriggeredFunction", + "Arn" ] - } - } + }, + "FilterPattern": "My filter pattern", + "LogGroupName": "MyCWLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "TriggeredFunctionCWLogEventPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "TriggeredFunction" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -86,7 +55,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/cognito_userpool_with_event.json b/tests/translator/output/aws-us-gov/cognito_userpool_with_event.json index cb8b915f83..13f4502936 100644 --- a/tests/translator/output/aws-us-gov/cognito_userpool_with_event.json +++ b/tests/translator/output/aws-us-gov/cognito_userpool_with_event.json @@ -1,53 +1,6 @@ { "Resources": { - "UserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "LambdaConfig": { - "PreSignUp": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - }, - "PostConfirmation": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - }, - "VerifyAuthChallengeResponse": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - } - }, - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ], - "UserAttributeUpdateSettings": { - "AttributesRequireVerificationBeforeUpdate": [ - "email" - ] - }, - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName" - } - }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -67,13 +20,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionCognitoPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "UserPool", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -86,7 +54,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -97,23 +66,54 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionCognitoPermission": { - "Type": "AWS::Lambda::Permission", + "UserPool": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" + "LambdaConfig": { + "PostConfirmation": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + }, + "PreSignUp": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + }, + "VerifyAuthChallengeResponse": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + } }, - "Principal": "cognito-idp.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "UserPool", - "Arn" + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserAttributeUpdateSettings": { + "AttributesRequireVerificationBeforeUpdate": [ + "email" ] - } - } + }, + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/congito_userpool_with_sms_configuration.json b/tests/translator/output/aws-us-gov/congito_userpool_with_sms_configuration.json index d08992be57..8e8734dc32 100644 --- a/tests/translator/output/aws-us-gov/congito_userpool_with_sms_configuration.json +++ b/tests/translator/output/aws-us-gov/congito_userpool_with_sms_configuration.json @@ -1,32 +1,6 @@ { "Resources": { - "MyCognitoUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "LambdaConfig": { - "PreSignUp": { - "Fn::GetAtt": [ - "HelloWorldFunction", - "Arn" - ] - } - }, - "SmsConfiguration": { - "SnsCallerArn": { - "Fn::GetAtt": [ - "UserPoolRole", - "Arn" - ] - }, - "ExternalId": { - "Ref": "ExternalId" - } - }, - "UserPoolName": "PreSignup" - } - }, "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -46,13 +20,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionCognitoPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyCognitoUserPool", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +54,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,23 +66,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "HelloWorldFunctionCognitoPermission": { - "Type": "AWS::Lambda::Permission", + "MyCognitoUserPool": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HelloWorldFunction" + "LambdaConfig": { + "PreSignUp": { + "Fn::GetAtt": [ + "HelloWorldFunction", + "Arn" + ] + } }, - "Principal": "cognito-idp.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "MyCognitoUserPool", - "Arn" - ] - } - } + "SmsConfiguration": { + "ExternalId": { + "Ref": "ExternalId" + }, + "SnsCallerArn": { + "Fn::GetAtt": [ + "UserPoolRole", + "Arn" + ] + } + }, + "UserPoolName": "PreSignup" + }, + "Type": "AWS::Cognito::UserPool" } } } diff --git a/tests/translator/output/aws-us-gov/connector_api_to_function.json b/tests/translator/output/aws-us-gov/connector_api_to_function.json index f28841e129..40417f8b3d 100644 --- a/tests/translator/output/aws-us-gov/connector_api_to_function.json +++ b/tests/translator/output/aws-us-gov/connector_api_to_function.json @@ -15,7 +15,10 @@ "Type": "MOCK" }, "ResourceId": { - "Fn::GetAtt": ["MyApiGateway", "RootResourceId"] + "Fn::GetAtt": [ + "MyApiGateway", + "RootResourceId" + ] }, "RestApiId": { "Ref": "MyApiGateway" @@ -46,17 +49,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyServerlessFunction", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyApiGatewayV2" - }, - "SourceQualifier": "*" + } } ] } @@ -79,17 +85,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyServerlessFunction", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyApiGateway" - }, - "SourceQualifier": "*" + } } ] } @@ -112,17 +121,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyServerlessApi" - }, - "SourceQualifier": "*" + } } ] } @@ -145,17 +157,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyHttpApi" - }, - "SourceQualifier": "*" + } } ] } @@ -169,7 +184,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -243,7 +261,9 @@ "swagger": "2.0" }, "EndpointConfiguration": { - "Types": ["REGIONAL"] + "Types": [ + "REGIONAL" + ] }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" @@ -280,7 +300,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -297,10 +320,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-us-gov/connector_bucket_to_function.json b/tests/translator/output/aws-us-gov/connector_bucket_to_function.json index a08455463d..665701e941 100644 --- a/tests/translator/output/aws-us-gov/connector_bucket_to_function.json +++ b/tests/translator/output/aws-us-gov/connector_bucket_to_function.json @@ -1,7 +1,9 @@ { "Resources": { "Bucket": { - "DependsOn": ["MyConnectorWriteLambdaPermission"], + "DependsOn": [ + "MyConnectorWriteLambdaPermission" + ], "Properties": { "BucketName": "random-bucket-name", "NotificationConfiguration": { @@ -9,7 +11,10 @@ { "Event": "s3:ObjectCreated:*", "Function": { - "Fn::GetAtt": ["InvokedFunction", "Arn"] + "Fn::GetAtt": [ + "InvokedFunction", + "Arn" + ] } } ] @@ -24,7 +29,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["FunctionRole", "Arn"] + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -41,10 +49,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -78,7 +90,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["Function", "Arn"] + "Fn::GetAtt": [ + "Function", + "Arn" + ] }, "Principal": "s3.amazonaws.com", "SourceAccount": { diff --git a/tests/translator/output/aws-us-gov/connector_esm_dependson.json b/tests/translator/output/aws-us-gov/connector_esm_dependson.json index b63e9a587d..f5be6465e5 100644 --- a/tests/translator/output/aws-us-gov/connector_esm_dependson.json +++ b/tests/translator/output/aws-us-gov/connector_esm_dependson.json @@ -1,255 +1,313 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Role": { - "Ref": "SomeRole" - } - } - }, - "MyQueue1": { - "Type": "AWS::SQS::Queue" - }, - "MyQueue2": { - "Type": "AWS::SQS::Queue" - }, - "MyQueue3": { - "Type": "AWS::SQS::Queue" - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table" - }, - "MyEventSourceMapping1": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue1", "Arn"] - } - }, - "DependsOn": ["MyConnector1Policy"] - }, - "MyEventSourceMapping2": { - "DependsOn": ["SomeDep", "MyConnector2Policy"], - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue2", "Arn"] - } - } - }, - "MyEventSourceMapping3": { - "DependsOn": ["SomeOtherDep", "MyConnector3Policy"], - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue3", "Arn"] - } - } - }, - "MyEventSourceMapping4": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] - } - }, - "DependsOn": ["MyConnector4Policy"] - }, "MyConnector1Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector1": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector2Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector2": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector3Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector3": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue3", "Arn"] + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue3", "Arn"] + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector4Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector4": { - "Source": { - "Type": "AWS::DynamoDB::Table" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::DynamoDB::Table" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "dynamodb:DescribeStream", "dynamodb:GetRecords", "dynamodb:GetShardIterator", "dynamodb:ListStreams" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyEventSourceMapping1": { + "DependsOn": [ + "MyConnector1Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping2": { + "DependsOn": [ + "SomeDep", + "MyConnector2Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping3": { + "DependsOn": [ + "SomeOtherDep", + "MyConnector3Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping4": { + "DependsOn": [ + "MyConnector4Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunction": { + "Properties": { + "Role": { + "Ref": "SomeRole" + } + }, + "Type": "AWS::Lambda::Function" + }, + "MyQueue1": { + "Type": "AWS::SQS::Queue" + }, + "MyQueue2": { + "Type": "AWS::SQS::Queue" + }, + "MyQueue3": { + "Type": "AWS::SQS::Queue" + }, + "MyTable": { + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/aws-us-gov/connector_function_to_s3.json b/tests/translator/output/aws-us-gov/connector_function_to_s3.json index 3a5cdc68f3..f5b3735be1 100644 --- a/tests/translator/output/aws-us-gov/connector_function_to_s3.json +++ b/tests/translator/output/aws-us-gov/connector_function_to_s3.json @@ -38,14 +38,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/*", { "DestinationArn": { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] } } ] @@ -65,14 +71,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/*", { "DestinationArn": { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] } } ] @@ -97,7 +109,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -114,10 +129,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-us-gov/connector_function_to_sqs.json b/tests/translator/output/aws-us-gov/connector_function_to_sqs.json index 3d93ffe75f..58072618aa 100644 --- a/tests/translator/output/aws-us-gov/connector_function_to_sqs.json +++ b/tests/translator/output/aws-us-gov/connector_function_to_sqs.json @@ -17,11 +17,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -62,7 +68,10 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -94,11 +103,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] }, @@ -112,7 +127,10 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -141,7 +159,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -176,7 +197,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -193,10 +217,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-us-gov/connector_function_to_table.json b/tests/translator/output/aws-us-gov/connector_function_to_table.json index cca9cf60d6..198190db7b 100644 --- a/tests/translator/output/aws-us-gov/connector_function_to_table.json +++ b/tests/translator/output/aws-us-gov/connector_function_to_table.json @@ -28,14 +28,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -81,14 +87,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -108,14 +120,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -161,14 +179,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -214,14 +238,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -253,7 +283,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -292,7 +325,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -309,10 +345,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-us-gov/connector_hardcoded_lambda_arn.json b/tests/translator/output/aws-us-gov/connector_hardcoded_lambda_arn.json index 1684af6d04..3da2074e63 100644 --- a/tests/translator/output/aws-us-gov/connector_hardcoded_lambda_arn.json +++ b/tests/translator/output/aws-us-gov/connector_hardcoded_lambda_arn.json @@ -19,7 +19,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["SomeLambda", "Arn"] + "Fn::GetAtt": [ + "SomeLambda", + "Arn" + ] }, "Principal": "sns.amazonaws.com", "SourceArn": { diff --git a/tests/translator/output/aws-us-gov/connector_hardcoded_props.json b/tests/translator/output/aws-us-gov/connector_hardcoded_props.json index 6571e85f5c..35916275e8 100644 --- a/tests/translator/output/aws-us-gov/connector_hardcoded_props.json +++ b/tests/translator/output/aws-us-gov/connector_hardcoded_props.json @@ -1,234 +1,201 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function" - }, - "MyRule": { - "Type": "AWS::Events::Rule" - }, - "MyQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyTopic": { - "Type": "AWS::SNS::Topic" - }, - "MyApiV1": { - "Type": "AWS::ApiGateway::RestApi" - }, - "MyApiV2": { - "Type": "AWS::ApiGatewayV2::Api" - }, - "MySfn": { - "Type": "AWS::StepFunctions::StateMachine" - }, - "RuleToTopicTopicPolicy": { - "Type": "AWS::SNS::TopicPolicy", + "ApiV1ToLambdaWriteLambdaPermission": { "Metadata": { "aws:sam:connectors": { - "RuleToTopic": { - "Source": { - "Type": "AWS::Events::Rule" - }, + "ApiV1ToLambda": { "Destination": { - "Type": "AWS::SNS::Topic" + "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::ApiGateway::RestApi" } } } }, "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { - "Effect": "Allow", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Resource": { - "Fn::GetAtt": ["Egg", "Baz"] - }, - "Action": "sns:Publish", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Fn::GetAtt": ["MyRule", "Arn"] - } - } + "SourceQualifier": "Prod/GET/foobar", + "SourceResourceId": { + "Ref": "MyApiV1" } } ] - }, - "Topics": [ - { - "Fn::GetAtt": ["Egg", "Baz"] - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, - "TopicToQueueQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "ApiV2ToLambdaWriteLambdaPermission": { "Metadata": { "aws:sam:connectors": { - "TopicToQueue": { - "Source": { - "Type": "AWS::SNS::Topic" - }, + "ApiV2ToLambda": { "Destination": { - "Type": "AWS::SQS::Queue" + "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::ApiGatewayV2::Api" } } } }, "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { - "Effect": "Allow", - "Principal": { - "Service": "sns.amazonaws.com" - }, - "Resource": { - "Ref": "MyQueue" - }, - "Action": "sqs:SendMessage", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "MyTopic" - } - } + "SourceQualifier": "*", + "SourceResourceId": { + "Ref": "MyApiV2" } } ] - }, - "Queues": [ - { - "Fn::If": [ - true, - { - "Ref": "Foo" - }, - { - "Ref": "Bar" - } - ] - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, "LambdaToQueuePolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "LambdaToQueue": { - "Source": { - "Type": "AWS::Lambda::Function" - }, "Destination": { "Type": "AWS::SQS::Queue" + }, + "Source": { + "Type": "AWS::Lambda::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "sqs:DeleteMessage", "sqs:SendMessage", "sqs:ChangeMessageVisibility", "sqs:PurgeQueue" ], + "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, - "Roles": ["MyCoolRole"] - } + "Roles": [ + "MyCoolRole" + ] + }, + "Type": "AWS::IAM::ManagedPolicy" }, - "ApiV1ToLambdaWriteLambdaPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiV1": { + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiV2": { + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyFunction": { + "Type": "AWS::Lambda::Function" + }, + "MyQueue": { + "Type": "AWS::SQS::Queue" + }, + "MyRule": { + "Type": "AWS::Events::Rule" + }, + "MySfn": { + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyTopic": { + "Type": "AWS::SNS::Topic" + }, + "RuleToTopicTopicPolicy": { "Metadata": { "aws:sam:connectors": { - "ApiV1ToLambda": { - "Source": { - "Type": "AWS::ApiGateway::RestApi" - }, + "RuleToTopic": { "Destination": { - "Type": "AWS::Lambda::Function" + "Type": "AWS::SNS::Topic" + }, + "Source": { + "Type": "AWS::Events::Rule" } } } }, "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", + "PolicyDocument": { + "Statement": [ { - "SourceResourceId": { - "Ref": "MyApiV1" + "Action": "sns:Publish", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Fn::GetAtt": [ + "MyRule", + "Arn" + ] + } + } }, - "SourceQualifier": "Prod/GET/foobar" - } - ] - } - } - }, - "ApiV2ToLambdaWriteLambdaPermission": { - "Type": "AWS::Lambda::Permission", - "Metadata": { - "aws:sam:connectors": { - "ApiV2ToLambda": { - "Source": { - "Type": "AWS::ApiGatewayV2::Api" - }, - "Destination": { - "Type": "AWS::Lambda::Function" + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "Egg", + "Baz" + ] + } } + ], + "Version": "2012-10-17" + }, + "Topics": [ + { + "Fn::GetAtt": [ + "Egg", + "Baz" + ] } - } + ] }, - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", - { - "SourceResourceId": { - "Ref": "MyApiV2" - }, - "SourceQualifier": "*" - } - ] - } - } + "Type": "AWS::SNS::TopicPolicy" }, "SfnToSfnPolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "SfnToSfn": { - "Source": { + "Destination": { "Type": "AWS::StepFunctions::StateMachine" }, - "Destination": { + "Source": { "Type": "AWS::StepFunctions::StateMachine" } } @@ -236,18 +203,22 @@ }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "states:DescribeExecution" + ], "Effect": "Allow", - "Action": ["states:DescribeExecution"], "Resource": [ { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", { "DestinationName": { - "Fn::GetAtt": ["MySfn", "Name"] + "Fn::GetAtt": [ + "MySfn", + "Name" + ] } } ] @@ -255,8 +226,10 @@ ] }, { + "Action": [ + "events:DescribeRule" + ], "Effect": "Allow", - "Action": ["events:DescribeRule"], "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" @@ -264,20 +237,29 @@ ] }, { + "Action": [ + "states:StartExecution" + ], "Effect": "Allow", - "Action": ["states:StartExecution"], - "Resource": ["some-other-arn"] + "Resource": [ + "some-other-arn" + ] }, { + "Action": [ + "states:StopExecution" + ], "Effect": "Allow", - "Action": ["states:StopExecution"], "Resource": [ { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", { "DestinationName": { - "Fn::GetAtt": ["MySfn", "Name"] + "Fn::GetAtt": [ + "MySfn", + "Name" + ] } } ] @@ -285,18 +267,77 @@ ] }, { + "Action": [ + "events:PutTargets", + "events:PutRule" + ], "Effect": "Allow", - "Action": ["events:PutTargets", "events:PutRule"], "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" } ] } - ] + ], + "Version": "2012-10-17" + }, + "Roles": [ + "MyRoleNice" + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "TopicToQueueQueuePolicy": { + "Metadata": { + "aws:sam:connectors": { + "TopicToQueue": { + "Destination": { + "Type": "AWS::SQS::Queue" + }, + "Source": { + "Type": "AWS::SNS::Topic" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "MyTopic" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "sns.amazonaws.com" + }, + "Resource": { + "Ref": "MyQueue" + } + } + ], + "Version": "2012-10-17" }, - "Roles": ["MyRoleNice"] - } + "Queues": [ + { + "Fn::If": [ + true, + { + "Ref": "Foo" + }, + { + "Ref": "Bar" + } + ] + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" } } } diff --git a/tests/translator/output/aws-us-gov/connector_hardcoded_rolename.json b/tests/translator/output/aws-us-gov/connector_hardcoded_rolename.json index 50677aded3..a9abcfc43a 100644 --- a/tests/translator/output/aws-us-gov/connector_hardcoded_rolename.json +++ b/tests/translator/output/aws-us-gov/connector_hardcoded_rolename.json @@ -26,14 +26,19 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } ], "Version": "2012-10-17" }, - "Roles": ["MyCoolRole"] + "Roles": [ + "MyCoolRole" + ] }, "Type": "AWS::IAM::ManagedPolicy" }, @@ -44,7 +49,10 @@ }, "Handler": "foo", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "python3.9", "Tags": [ @@ -61,10 +69,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/aws-us-gov/connector_rule_to_eventbus.json b/tests/translator/output/aws-us-gov/connector_rule_to_eventbus.json index e4c3f79d6b..462ea044dd 100644 --- a/tests/translator/output/aws-us-gov/connector_rule_to_eventbus.json +++ b/tests/translator/output/aws-us-gov/connector_rule_to_eventbus.json @@ -25,11 +25,16 @@ "PolicyDocument": { "Statement": [ { - "Action": ["events:PutEvents"], + "Action": [ + "events:PutEvents" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["EventBus", "Arn"] + "Fn::GetAtt": [ + "EventBus", + "Arn" + ] } ] } @@ -61,7 +66,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["events:PutEvents"], + "Action": [ + "events:PutEvents" + ], "Effect": "Allow", "Resource": [ { @@ -83,18 +90,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["EventBus", "Arn"] + "Fn::GetAtt": [ + "EventBus", + "Arn" + ] }, "Id": "EventBus", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] @@ -104,7 +119,9 @@ "MyNewEventsRuleToDefaultBus": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", @@ -115,7 +132,10 @@ }, "Id": "EventBus", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] diff --git a/tests/translator/output/aws-us-gov/connector_rule_to_sfn.json b/tests/translator/output/aws-us-gov/connector_rule_to_sfn.json index f5b90955d8..f5703dba97 100644 --- a/tests/translator/output/aws-us-gov/connector_rule_to_sfn.json +++ b/tests/translator/output/aws-us-gov/connector_rule_to_sfn.json @@ -17,7 +17,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["states:StartExecution"], + "Action": [ + "states:StartExecution" + ], "Effect": "Allow", "Resource": [ { @@ -39,18 +41,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["StateMachine", "Arn"] + "Fn::GetAtt": [ + "StateMachine", + "Arn" + ] }, "Id": "StateMachine", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] @@ -96,11 +106,17 @@ }, "DefinitionSubstitutions": { "definition_substitution_1": { - "Fn::GetAtt": ["StateMachineFunction", "Arn"] + "Fn::GetAtt": [ + "StateMachineFunction", + "Arn" + ] } }, "RoleArn": { - "Fn::GetAtt": ["StateMachineRole", "Arn"] + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] }, "StateMachineType": "EXPRESS", "Tags": [ @@ -117,10 +133,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["states.amazonaws.com"] + "Service": [ + "states.amazonaws.com" + ] } } ], @@ -132,7 +152,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ diff --git a/tests/translator/output/aws-us-gov/connector_rule_to_sns.json b/tests/translator/output/aws-us-gov/connector_rule_to_sns.json index 78fd335694..cffbb77f04 100644 --- a/tests/translator/output/aws-us-gov/connector_rule_to_sns.json +++ b/tests/translator/output/aws-us-gov/connector_rule_to_sns.json @@ -21,7 +21,10 @@ "Condition": { "ArnEquals": { "aws:SourceArn": { - "Fn::GetAtt": ["MyNewEventsRule", "Arn"] + "Fn::GetAtt": [ + "MyNewEventsRule", + "Arn" + ] } } }, @@ -47,18 +50,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["StateMachine", "Arn"] + "Fn::GetAtt": [ + "StateMachine", + "Arn" + ] }, "Id": "StateMachine", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] diff --git a/tests/translator/output/aws-us-gov/connector_samfunction_to_table.json b/tests/translator/output/aws-us-gov/connector_samfunction_to_table.json index fb25e66506..707cae689c 100644 --- a/tests/translator/output/aws-us-gov/connector_samfunction_to_table.json +++ b/tests/translator/output/aws-us-gov/connector_samfunction_to_table.json @@ -1,34 +1,57 @@ { "Resources": { - "MyTable": { - "Type": "AWS::DynamoDB::Table", + "MyConnectorPolicy": { "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "AttributeDefinitions": [ - { - "AttributeName": "Id", - "AttributeType": "S" - } - ], - "KeySchema": [ + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", + "dynamodb:BatchGetItem", + "dynamodb:ConditionCheckItem", + "dynamodb:PartiQLSelect" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + }, + { + "Fn::Sub": [ + "${DestinationArn}/index/*", + { + "DestinationArn": { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + } + } + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ { - "AttributeName": "Id", - "KeyType": "HASH" + "Ref": "MyFunctionRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n const docClient = new AWS.DynamoDB.DocumentClient();\n await docClient.scan({ TableName: process.env.TABLE_NAME, }).promise();\n};\n" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] - }, - "Runtime": "nodejs14.x", "Environment": { "Variables": { "TABLE_NAME": { @@ -36,28 +59,40 @@ } } }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -68,48 +103,26 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", + "MyTable": { "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "dynamodb:GetItem", - "dynamodb:Query", - "dynamodb:Scan", - "dynamodb:BatchGetItem", - "dynamodb:ConditionCheckItem", - "dynamodb:PartiQLSelect" - ], - "Resource": [ - { - "Fn::GetAtt": ["MyTable", "Arn"] - }, - { - "Fn::Sub": [ - "${DestinationArn}/index/*", - { - "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] - } - } - ] - } - ] - } - ] - }, - "Roles": [ + "AttributeDefinitions": [ { - "Ref": "MyFunctionRole" + "AttributeName": "Id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "Id", + "KeyType": "HASH" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/aws-us-gov/connector_sfn_to_function.json b/tests/translator/output/aws-us-gov/connector_sfn_to_function.json index 1da3395523..98ace1cbd9 100644 --- a/tests/translator/output/aws-us-gov/connector_sfn_to_function.json +++ b/tests/translator/output/aws-us-gov/connector_sfn_to_function.json @@ -17,11 +17,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeAsync", "lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeAsync", + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } ] } @@ -43,7 +49,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -60,10 +69,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -102,11 +115,17 @@ }, "DefinitionSubstitutions": { "definition_substitution_1": { - "Fn::GetAtt": ["StateMachineFunction", "Arn"] + "Fn::GetAtt": [ + "StateMachineFunction", + "Arn" + ] } }, "RoleArn": { - "Fn::GetAtt": ["MyStateMachineRole", "Arn"] + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] }, "StateMachineType": "EXPRESS", "Tags": [ @@ -123,10 +142,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["states.amazonaws.com"] + "Service": [ + "states.amazonaws.com" + ] } } ], @@ -138,7 +161,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ diff --git a/tests/translator/output/aws-us-gov/connector_sfn_to_sfn.json b/tests/translator/output/aws-us-gov/connector_sfn_to_sfn.json index b9fb53b4cf..d79e529b0d 100644 --- a/tests/translator/output/aws-us-gov/connector_sfn_to_sfn.json +++ b/tests/translator/output/aws-us-gov/connector_sfn_to_sfn.json @@ -1,22 +1,119 @@ { "Resources": { - "TriggerStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "MyConnectorPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Destination": { + "Type": "AWS::Serverless::StateMachine" + }, + "Source": { + "Type": "AWS::Serverless::StateMachine" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "states:DescribeExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": [ + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", + { + "DestinationName": { + "Fn::GetAtt": [ + "MyStateMachine", + "Name" + ] + } + } + ] + } + ] + }, + { + "Action": [ + "events:DescribeRule" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" + } + ] + }, + { + "Action": [ + "states:StartExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Ref": "MyStateMachine" + } + ] + }, + { + "Action": [ + "states:StopExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": [ + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", + { + "DestinationName": { + "Fn::GetAtt": [ + "MyStateMachine", + "Name" + ] + } + } + ] + } + ] + }, + { + "Action": [ + "events:PutTargets", + "events:PutRule" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "TriggerStateMachineRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyStateMachine": { "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", - " \"StartAt\": \"TryDoSomething\",", + " \"StartAt\": \"Success\",", " \"States\": {", - " \"TryDoSomething\": {", - " \"End\": true,", - " \"Parameters\": {", - " \"StateMachineArn\": \"${definition_substitution_1}\"", - " },", - " \"Resource\": \"arn:aws:states:::states:startExecution.sync:2\",", - " \"Type\": \"Task\"", + " \"Success\": {", + " \"Type\": \"Succeed\"", " }", " }", "}" @@ -25,32 +122,23 @@ }, "RoleArn": { "Fn::GetAtt": [ - "TriggerStateMachineRole", + "MyStateMachineRole", "Arn" ] }, - "StateMachineType": "STANDARD", + "StateMachineType": "EXPRESS", "Tags": [ { "Key": "stateMachine:createdBy", "Value": "SAM" } - ], - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Ref": "MyStateMachine" - } - } + ] }, - "DependsOn": [ - "MyConnectorPolicy" - ] + "Type": "AWS::StepFunctions::StateMachine" }, - "TriggerStateMachineRole": { - "Type": "AWS::IAM::Role", + "MyStateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -63,19 +151,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "TriggerStateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -86,7 +174,8 @@ } } ] - } + }, + "PolicyName": "MyStateMachineRolePolicy0" } ], "Tags": [ @@ -95,46 +184,58 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "TriggerStateMachine": { + "DependsOn": [ + "MyConnectorPolicy" + ], "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", - " \"StartAt\": \"Success\",", + " \"StartAt\": \"TryDoSomething\",", " \"States\": {", - " \"Success\": {", - " \"Type\": \"Succeed\"", + " \"TryDoSomething\": {", + " \"End\": true,", + " \"Parameters\": {", + " \"StateMachineArn\": \"${definition_substitution_1}\"", + " },", + " \"Resource\": \"arn:aws:states:::states:startExecution.sync:2\",", + " \"Type\": \"Task\"", " }", " }", "}" ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Ref": "MyStateMachine" + } + }, "RoleArn": { "Fn::GetAtt": [ - "MyStateMachineRole", + "TriggerStateMachineRole", "Arn" ] }, - "StateMachineType": "EXPRESS", + "StateMachineType": "STANDARD", "Tags": [ { "Key": "stateMachine:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", + "TriggerStateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -147,19 +248,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "MyStateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -170,7 +271,8 @@ } } ] - } + }, + "PolicyName": "TriggerStateMachineRolePolicy0" } ], "Tags": [ @@ -179,110 +281,8 @@ "Value": "SAM" } ] - } - }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", - "Metadata": { - "aws:sam:connectors": { - "MyConnector": { - "Source": { - "Type": "AWS::Serverless::StateMachine" - }, - "Destination": { - "Type": "AWS::Serverless::StateMachine" - } - } - } }, - "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "states:DescribeExecution" - ], - "Resource": [ - { - "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", - { - "DestinationName": { - "Fn::GetAtt": [ - "MyStateMachine", - "Name" - ] - } - } - ] - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "events:DescribeRule" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "states:StartExecution" - ], - "Resource": [ - { - "Ref": "MyStateMachine" - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "states:StopExecution" - ], - "Resource": [ - { - "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", - { - "DestinationName": { - "Fn::GetAtt": [ - "MyStateMachine", - "Name" - ] - } - } - ] - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "events:PutTargets", - "events:PutRule" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" - } - ] - } - ] - }, - "Roles": [ - { - "Ref": "TriggerStateMachineRole" - } - ] - } + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/connector_sns_to_function.json b/tests/translator/output/aws-us-gov/connector_sns_to_function.json index e5054c69c2..d353e61557 100644 --- a/tests/translator/output/aws-us-gov/connector_sns_to_function.json +++ b/tests/translator/output/aws-us-gov/connector_sns_to_function.json @@ -16,7 +16,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "sns.amazonaws.com", "SourceArn": { @@ -39,7 +42,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, diff --git a/tests/translator/output/aws-us-gov/connector_sns_to_sqs.json b/tests/translator/output/aws-us-gov/connector_sns_to_sqs.json index 9b6063a4b9..556f77cd4e 100644 --- a/tests/translator/output/aws-us-gov/connector_sns_to_sqs.json +++ b/tests/translator/output/aws-us-gov/connector_sns_to_sqs.json @@ -33,7 +33,10 @@ "Service": "sns.amazonaws.com" }, "Resource": { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } } ], @@ -80,7 +83,10 @@ "Service": "sns.amazonaws.com" }, "Resource": { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } } ], @@ -99,13 +105,19 @@ "Subscription": [ { "Endpoint": { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] }, "Protocol": "sqs" }, { "Endpoint": { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] }, "Protocol": "sqs" } diff --git a/tests/translator/output/aws-us-gov/connector_sqs_to_function.json b/tests/translator/output/aws-us-gov/connector_sqs_to_function.json index 6d239c3f92..5c4592ae8d 100644 --- a/tests/translator/output/aws-us-gov/connector_sqs_to_function.json +++ b/tests/translator/output/aws-us-gov/connector_sqs_to_function.json @@ -17,20 +17,31 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:DeleteMessage"], + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] } ] }, { - "Action": ["sqs:GetQueueAttributes", "sqs:ReceiveMessage"], + "Action": [ + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] } ] } @@ -59,7 +70,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["InvokedFunctionRole", "Arn"] + "Fn::GetAtt": [ + "InvokedFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -76,10 +90,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -93,14 +111,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -124,11 +147,16 @@ "Type": "AWS::SQS::Queue" }, "SQSEventSourceMapping": { - "DependsOn": ["ConnectorPolicy"], + "DependsOn": [ + "ConnectorPolicy" + ], "Properties": { "BatchSize": 10, "EventSourceArn": { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] }, "FunctionName": { "Ref": "InvokedFunction" @@ -153,7 +181,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["TriggerFunctionRole", "Arn"] + "Fn::GetAtt": [ + "TriggerFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -171,10 +202,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -202,7 +237,10 @@ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -216,14 +254,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["Queue", "QueueName"] + "Fn::GetAtt": [ + "Queue", + "QueueName" + ] } } ] diff --git a/tests/translator/output/aws-us-gov/connector_table_to_function.json b/tests/translator/output/aws-us-gov/connector_table_to_function.json index e038dcb2b1..ed90208e1d 100644 --- a/tests/translator/output/aws-us-gov/connector_table_to_function.json +++ b/tests/translator/output/aws-us-gov/connector_table_to_function.json @@ -30,7 +30,10 @@ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -62,7 +65,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, diff --git a/tests/translator/output/aws-us-gov/connector_table_to_function_read.json b/tests/translator/output/aws-us-gov/connector_table_to_function_read.json index dfcd4e9ef4..9cfe3060da 100644 --- a/tests/translator/output/aws-us-gov/connector_table_to_function_read.json +++ b/tests/translator/output/aws-us-gov/connector_table_to_function_read.json @@ -29,14 +29,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] } } ] @@ -84,7 +90,10 @@ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] } } ] @@ -103,15 +112,23 @@ "Type": "AWS::IAM::ManagedPolicy" }, "DynamoDBTableStream": { - "DependsOn": ["ConnectorPolicy"], + "DependsOn": [ + "ConnectorPolicy" + ], "Properties": { "BatchSize": 1, "Enabled": true, "EventSourceArn": { - "Fn::GetAtt": ["Table", "StreamArn"] + "Fn::GetAtt": [ + "Table", + "StreamArn" + ] }, "FunctionName": { - "Fn::GetAtt": ["InvokedFunction", "Arn"] + "Fn::GetAtt": [ + "InvokedFunction", + "Arn" + ] }, "StartingPosition": "TRIM_HORIZON" }, @@ -131,7 +148,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["InvokedFunctionRole", "Arn"] + "Fn::GetAtt": [ + "InvokedFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -148,10 +168,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -165,14 +189,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -230,7 +259,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["TriggerFunctionRole", "Arn"] + "Fn::GetAtt": [ + "TriggerFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -248,10 +280,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -279,7 +315,10 @@ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] diff --git a/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json b/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json index e8693dc49e..31d11e6717 100644 --- a/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json +++ b/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json @@ -1,154 +1,154 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", - "Conditions": { - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", + "Resources": { + "HttpApiIfIntrinsicAndNoOpenApiEditor": { + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + } + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/" + } + } + } + } + } + ] } + }, + "Type": "AWS::ApiGatewayV2::Api" }, - "Resources": { - "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", - "RestApiId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" - }, - "StageName": "Stage" - } - }, - "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" - }, - "RestApiId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" - }, - "StageName": "prod" - } + "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { + "Properties": { + "ApiId": { + "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" }, - "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" - }, - "StageName": "prod", - "AutoDeploy": true - } - }, - "RestApiIfIntrinsicAndNoSwaggerEditor": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "Fn::If": [ - "FalseCondition", - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "swagger": "2.0" - }, - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otheruri.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "swagger": "2.0" - } - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] + "AutoDeploy": true, + "StageName": "prod" + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "RestApiIfIntrinsicAndNoSwaggerEditor": { + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" } - } - }, - "HttpApiIfIntrinsicAndNoOpenApiEditor": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "Fn::If": [ - "FalseCondition", - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "openapi": "3.0" - }, - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otheruri.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "openapi": "3.0" - } - ] + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + }, + "swagger": "2.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/" + } + } + } + }, + "swagger": "2.0" } + ] + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { + "Properties": { + "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" + }, + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "prod" + }, + "Type": "AWS::ApiGateway::Stage" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/depends_on.json b/tests/translator/output/aws-us-gov/depends_on.json index 6e12829637..f8a285c95f 100644 --- a/tests/translator/output/aws-us-gov/depends_on.json +++ b/tests/translator/output/aws-us-gov/depends_on.json @@ -1,7 +1,50 @@ { "Resources": { + "MyExplicitApi": { + "DependsOn": "MySamTable", + "Properties": { + "BodyS3Location": { + "Bucket": "sam-translator-tests-dont-delete", + "Key": "swagger-http.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyExplicitApiDeployment74b681ce04": { + "Properties": { + "Description": "RestApi deployment id: 74b681ce04601a2cf69b6d05d53782b216cf96bb", + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyExplicitApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyExplicitApiDeployment74b681ce04" + }, + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", + "DependsOn": [ + "MyExplicitApi", + "MySamTable" + ], "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,147 +60,104 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyExplicitApi", - "MySamTable" - ] + "Type": "AWS::Lambda::Function" }, - "MyExplicitApiDeployment74b681ce04": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionMyApiPermissiondev": { "Properties": { - "RestApiId": { - "Ref": "MyExplicitApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Description": "RestApi deployment id: 74b681ce04601a2cf69b6d05d53782b216cf96bb", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "MyExplicitApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionRole": { "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-translator-tests-dont-delete", - "Key": "swagger-http.json" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "DependsOn": "MySamTable" + "Type": "AWS::IAM::Role" }, "MyOtherTable": { - "Type": "AWS::DynamoDB::Table", + "DependsOn": "MySamTable", "Properties": { - "KeySchema": [ + "AttributeDefinitions": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "AttributeType": "S" } ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "KeySchema": [ { "AttributeName": "id", - "AttributeType": "S" + "KeyType": "HASH" } ], "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" } }, - "DependsOn": "MySamTable" - }, - "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyExplicitApiDeployment74b681ce04" - }, - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "StageName": "dev" - } + "Type": "AWS::DynamoDB::Table" }, "MySamTable": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "MyExplicitApi" - } - ] - } - } + }, + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/aws-us-gov/error_function_with_invalid_stream_eventsource_dest_type.json b/tests/translator/output/aws-us-gov/error_function_with_invalid_stream_eventsource_dest_type.json index dc4f300bdf..f52c232d90 100644 --- a/tests/translator/output/aws-us-gov/error_function_with_invalid_stream_eventsource_dest_type.json +++ b/tests/translator/output/aws-us-gov/error_function_with_invalid_stream_eventsource_dest_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/aws-us-gov/error_function_with_missing_on_failure_in_stream_event_destination_config.json b/tests/translator/output/aws-us-gov/error_function_with_missing_on_failure_in_stream_event_destination_config.json index dcc5d33fb1..a60f6883d3 100644 --- a/tests/translator/output/aws-us-gov/error_function_with_missing_on_failure_in_stream_event_destination_config.json +++ b/tests/translator/output/aws-us-gov/error_function_with_missing_on_failure_in_stream_event_destination_config.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/aws-us-gov/eventbridgerule.json b/tests/translator/output/aws-us-gov/eventbridgerule.json index 799d38946d..f35727a8d3 100644 --- a/tests/translator/output/aws-us-gov/eventbridgerule.json +++ b/tests/translator/output/aws-us-gov/eventbridgerule.json @@ -1,185 +1,185 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/eventbridgerule_schedule_properties.json b/tests/translator/output/aws-us-gov/eventbridgerule_schedule_properties.json index 6a6eef9ce9..0b43e27f21 100644 --- a/tests/translator/output/aws-us-gov/eventbridgerule_schedule_properties.json +++ b/tests/translator/output/aws-us-gov/eventbridgerule_schedule_properties.json @@ -1,93 +1,120 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -95,93 +122,66 @@ "terminated" ] } - }, + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Name": "test-schedule", - "Description": "Test Schedule", - "State": "ENABLED", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json b/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json index 17da23c66c..ae05248380 100644 --- a/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json +++ b/tests/translator/output/aws-us-gov/eventbridgerule_with_dlq.json @@ -1,240 +1,240 @@ { "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ScheduledFunctionScheduleQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Queues": [ + "ScheduleExpression": "rate(1 minute)", + "State": "ENABLED", + "Targets": [ { - "Ref": "ScheduledFunctionScheduleQueue" + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "DeadLetterConfig": { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunctionScheduleQueue", + "Arn" + ] + } + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" } - ], + ] + }, + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionScheduleQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "ScheduledFunctionScheduleQueuePolicy": { + "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "ScheduledFunctionScheduleQueue", - "Arn" - ] - }, - "Effect": "Allow", + "Action": "sqs:SendMessage", "Condition": { "ArnEquals": { "aws:SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } } - }, + }, + "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "ScheduledFunctionScheduleQueue", + "Arn" + ] } } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "ScheduledFunctionScheduleQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "TriggeredFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TriggeredFunctionRole", + "Arn" ] - } - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", - "State" : "ENABLED", + }, + "State": "ENABLED", "Targets": [ { - "DeadLetterConfig": { - "Arn": "ARN" - }, - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "DeadLetterConfig": { + "Arn": "ARN" + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "TriggeredFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", + "TriggeredFunctionOnTerminate", "Arn" ] } - } - }, - "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule", - "Arn" - ] - } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { - "Fn::GetAtt": [ - "ScheduledFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionScheduleQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { - "Fn::GetAtt": [ - "TriggeredFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "State" : "ENABLED", - "Targets": [ - { - "DeadLetterConfig": { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunctionScheduleQueue", - "Arn" - ] - } - }, - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/eventbridgerule_with_retry_policy.json b/tests/translator/output/aws-us-gov/eventbridgerule_with_retry_policy.json index d904833c33..f57680f110 100644 --- a/tests/translator/output/aws-us-gov/eventbridgerule_with_retry_policy.json +++ b/tests/translator/output/aws-us-gov/eventbridgerule_with_retry_policy.json @@ -1,189 +1,189 @@ { "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - }, + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 200, + "MaximumEventAgeInSeconds": 200, "MaximumRetryAttempts": 3 } } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/explicit_api.json b/tests/translator/output/aws-us-gov/explicit_api.json index 5c2d3ec05b..14ff0657f1 100644 --- a/tests/translator/output/aws-us-gov/explicit_api.json +++ b/tests/translator/output/aws-us-gov/explicit_api.json @@ -1,179 +1,178 @@ { "Parameters": { - "something": { - "Default": "something", - "Type": "String" - }, "MyStageName": { - "Default": "Production", + "Default": "Production", + "Type": "String" + }, + "something": { + "Default": "something", "Type": "String" } - }, + }, "Resources": { - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "ApiWithInlineSwagger": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "webpage.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Body": { + "a": "inline swagger", + "this": "is" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiWithInlineSwaggerDeployment09cda3d97b": { + "Properties": { + "Description": "RestApi deployment id: 09cda3d97b008bed7bd4ebb1b5304ed622492941", + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiWithInlineSwaggerStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithInlineSwaggerDeployment09cda3d97b" - }, + }, "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, + }, "StageName": { "Ref": "MyStageName" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "MyGetApi", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", "RestApiId": { "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + }, "StageName": "Stage" - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "EndpointUri": { + "Ref": "something" + }, + "EndpointUri2": "http://example.com" } - } - }, - "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "Body": { - "this": "is", - "a": "inline swagger" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "webpage.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "GetHtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "GetHtmlApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": "MyGetApi" - } - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "EndpointUri": { - "Ref": "something" - }, - "EndpointUri2": "http://example.com" - }, - "StageName": { - "Ref": "MyStageName" - } - } - }, - "ApiWithInlineSwaggerDeployment09cda3d97b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 09cda3d97b008bed7bd4ebb1b5304ed622492941", - "StageName": "Stage" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/explicit_api_openapi_3.json b/tests/translator/output/aws-us-gov/explicit_api_openapi_3.json index 49592d0b2e..5383290e61 100644 --- a/tests/translator/output/aws-us-gov/explicit_api_openapi_3.json +++ b/tests/translator/output/aws-us-gov/explicit_api_openapi_3.json @@ -1,178 +1,177 @@ { "Parameters": { - "something": { - "Default": "something", - "Type": "String" - }, "MyStageName": { - "Default": "Production", + "Default": "Production", + "Type": "String" + }, + "something": { + "Default": "something", "Type": "String" } - }, + }, "Resources": { - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "ApiWithInlineSwagger": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "webpage.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Body": { + "a": "inline swagger", + "this": "is" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiWithInlineSwaggerDeployment74abcb3a5b": { + "Properties": { + "Description": "RestApi deployment id: 74abcb3a5bbe7ad58dfc543740af3be156736130", + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiWithInlineSwaggerStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithInlineSwaggerDeployment74abcb3a5b" - }, + }, "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, + }, "StageName": { "Ref": "MyStageName" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "MyGetApi", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" }, "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", "RestApiId": { "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + }, "StageName": "Stage" - } - }, - "ApiWithInlineSwaggerDeployment74abcb3a5b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 74abcb3a5bbe7ad58dfc543740af3be156736130" - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "EndpointUri": { + "Ref": "something" + }, + "EndpointUri2": "http://example.com" + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "webpage.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "inline swagger" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "GetHtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "GetHtmlApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": "MyGetApi" - } - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "EndpointUri": { - "Ref": "something" - }, - "EndpointUri2": "http://example.com" - }, - "StageName": { - "Ref": "MyStageName" - } - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/explicit_api_with_invalid_events_config.json b/tests/translator/output/aws-us-gov/explicit_api_with_invalid_events_config.json index be3dbcbf98..074ae53be4 100644 --- a/tests/translator/output/aws-us-gov/explicit_api_with_invalid_events_config.json +++ b/tests/translator/output/aws-us-gov/explicit_api_with_invalid_events_config.json @@ -1,134 +1,134 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionAddApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", - { - "__Stage__": "*", - "__ApiId__": "ApiWithInlineSwagger" - } - ] - } - } - }, - "ApiWithInlineSwaggerProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiWithInlineSwaggerDeployment22d399868d" - }, - "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "StageName": "Prod" - } - }, "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/foo": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ApiWithInlineSwaggerDeployment22d399868d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 22d399868d5755a0d5204deae1ee870cf95a7737", "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 22d399868d5755a0d5204deae1ee870cf95a7737", + }, "StageName": "Stage" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiWithInlineSwaggerProdStage": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "DeploymentId": { + "Ref": "ApiWithInlineSwaggerDeployment22d399868d" + }, + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAddApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + { + "__ApiId__": "ApiWithInlineSwagger", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/explicit_http_api.json b/tests/translator/output/aws-us-gov/explicit_http_api.json index e3ff6cce64..d996571760 100644 --- a/tests/translator/output/aws-us-gov/explicit_http_api.json +++ b/tests/translator/output/aws-us-gov/explicit_http_api.json @@ -1,258 +1,258 @@ { "Resources": { - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunctionBasePathPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Apiv2" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "ANY", - "type": "http_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "isDefaultRoute": true, - "security": [ - { - "OAuth2": [] - } - ] - } - }, - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "OAuth2": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "OAuth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Ref": "MyApi2" + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionBasePathPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApi2" - } + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { - "FailOnWarnings": true, "Body": { + "components": { + "securitySchemes": { + "OAuth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, + "isDefaultRoute": true, + "responses": {}, "security": [ { "OAuth2": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } } - }, - "openapi": "3.0.1", + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + }, + "FailOnWarnings": true + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2": { + "Properties": { + "Body": { "components": { "securitySchemes": { "OAuth2": { - "type": "oauth2", + "type": "oauth2", "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", + "identitySource": "$request.querystring.param", "jwtConfiguration": { "audience": [ "MyApi" - ], + ], "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Apiv2" + } + }, + "openapi": "3.0", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "security": [ + { + "OAuth2": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "payloadFormatVersion": "1.0", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/" + } + } + }, + "/": { + "get": { + "responses": {}, + "security": [ + { + "OAuth2": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } } } } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/explicit_http_api_minimum.json b/tests/translator/output/aws-us-gov/explicit_http_api_minimum.json index df8e5fcfb1..215cd7c832 100644 --- a/tests/translator/output/aws-us-gov/explicit_http_api_minimum.json +++ b/tests/translator/output/aws-us-gov/explicit_http_api_minimum.json @@ -1,161 +1,161 @@ { "Resources": { + "Api": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "Api" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "Api": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], - "paths": {}, - "openapi": "3.0.1" - } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, - "openapi": "3.0.1" + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] } - } - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "Api" - }, - "AutoDeploy": true, - "StageName": "$default", + }, + "AutoDeploy": true, + "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/function_concurrency.json b/tests/translator/output/aws-us-gov/function_concurrency.json index 9eb5d9f576..5344df2f90 100644 --- a/tests/translator/output/aws-us-gov/function_concurrency.json +++ b/tests/translator/output/aws-us-gov/function_concurrency.json @@ -5,20 +5,35 @@ } }, "Resources": { - "ConcurrentFunctionRole": { - "Type": "AWS::IAM::Role", + "AnotherFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": { + "Ref": "Concurrency" + }, + "Role": { + "Fn::GetAtt": [ + "AnotherFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "AnotherFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -30,18 +45,30 @@ "lambda.amazonaws.com" ] } - }] - } - } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ConcurrentFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "ConcurrentFunctionRole", @@ -49,27 +76,18 @@ ] }, "Runtime": "python2.7", - "ReservedConcurrentExecutions": 100, - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "AnotherFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ConcurrentFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -81,33 +99,21 @@ "lambda.amazonaws.com" ] } - }] - } - } - }, - "AnotherFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + } + ], + "Version": "2012-10-17" }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "AnotherFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "ReservedConcurrentExecutions": { - "Ref": "Concurrency" - }, - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_event_conditions.json b/tests/translator/output/aws-us-gov/function_event_conditions.json index d35bfe484b..1b5a0be94a 100644 --- a/tests/translator/output/aws-us-gov/function_event_conditions.json +++ b/tests/translator/output/aws-us-gov/function_event_conditions.json @@ -8,371 +8,473 @@ } }, "Resources": { - "MyAwesomeFunctionAliasLive": { - "Type": "AWS::Lambda::Alias", - "Condition": "MyCondition", + "FunctionOne": { "Properties": { - "FunctionVersion": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { "Fn::GetAtt": [ - "MyAwesomeFunctionVersion640128d35d", - "Version" + "FunctionOneRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "MyAwesomeFunction" - }, - "Name": "Live" - } - }, - "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionOneImageBucketPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Ref": "Notifications" + "Ref": "FunctionOne" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionCWEventPermission": { - "Type": "AWS::Lambda::Permission", + "FunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "FunctionOneImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Fn::If": [ + "MyCondition", + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Ref": "MyAwesomeFunctionAliasLive" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionOne", + "Arn" + ] + } + } + ] + }, + "Tags": [ + { + "Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission", + "Value": { + "Fn::If": [ + "MyCondition", + { + "Ref": "MyAwesomeFunctionS3TriggerPermission" + }, + "no dependency" + ] + } + } + ] + }, + "Type": "AWS::S3::Bucket" + }, + "MyAwesomeFunction": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "MyAwesomeFunctionCWEvent", + "MyAwesomeFunctionRole", "Arn" ] - } - } + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyAwesomeFunctionEBRulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionAliasLive": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" + "Ref": "MyAwesomeFunction" }, - "SourceArn": { + "FunctionVersion": { "Fn::GetAtt": [ - "MyAwesomeFunctionEBRule", + "MyAwesomeFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "Live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyAwesomeFunctionAnotherSNSWithSQSSubscription": { + "Condition": "MyCondition", + "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", "Arn" ] + }, + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" }, - "MyAwesomeFunctionDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionEventSourceMapping": { "Condition": "MyCondition", "Properties": { - "BatchSize": 200, - "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", + "Arn" + ] + }, "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "LATEST" - } + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionIoTRule": { - "Type": "AWS::IoT::TopicRule", + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue": { + "Condition": "MyCondition", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueuePolicy": { "Condition": "MyCondition", "Properties": { - "TopicRulePayload": { - "AwsIotSqlVersion": "beta", - "Actions": [ + "PolicyDocument": { + "Statement": [ { - "Lambda": { - "FunctionArn": { - "Ref": "MyAwesomeFunctionAliasLive" + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", + "Arn" + ] } } - ], - "RuleDisabled": false, - "Sql": "SELECT * FROM 'topic/test'" - } - } - }, - "MyAwesomeFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "MyAwesomeFunctionCWEvent": { "Condition": "MyCondition", "Properties": { - "BatchSize": 100, - "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "TRIM_HORIZON" - } + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionCWEventLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" }, - "MyAwesomeFunctionIoTRulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionCWEventPermission": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", - { - "RuleName": { - "Ref": "MyAwesomeFunctionIoTRule" - } - } + "Fn::GetAtt": [ + "MyAwesomeFunctionCWEvent", + "Arn" ] } - } - }, - "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", - "Condition": "MyCondition", - "Properties": { - "Endpoint": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Protocol": "lambda", - "TopicArn": { - "Ref": "Notifications" - } - } - }, - "MyAwesomeFunctionS3TriggerPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionCWLog": { "Condition": "MyCondition", + "DependsOn": [ + "MyAwesomeFunctionCWLogPermission" + ], "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { + "DestinationArn": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "Principal": "s3.amazonaws.com" - } + }, + "FilterPattern": "My pattern", + "LogGroupName": "MyLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "MyAwesomeFunctionCWLogPermission": { - "Type": "AWS::Lambda::Permission", "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", + "arn:aws-us-gov:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", { "__LogGroupName__": "MyLogGroup" } ] } - } - }, - "MyAwesomeFunctionEBSchedule": { - "Type": "AWS::Events::Rule", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionDDBStream": { "Condition": "MyCondition", "Properties": { - "ScheduleExpression": "rate(1 minute)", + "BatchSize": 200, + "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionEBRule": { + "Condition": "MyCondition", + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "launched" + ] + } + }, "Targets": [ { - "Id": "MyAwesomeFunctionEBScheduleLambdaTarget", "Arn": { "Ref": "MyAwesomeFunctionAliasLive" - } + }, + "Id": "MyAwesomeFunctionEBRuleLambdaTarget" } ] - } - }, - "MyAwesomeFunctionCWLog": { - "Type": "AWS::Logs::SubscriptionFilter", + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBRulePermission": { "Condition": "MyCondition", "Properties": { - "DestinationArn": { + "Action": "lambda:InvokeFunction", + "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "FilterPattern": "My pattern", - "LogGroupName": "MyLogGroup" - }, - "DependsOn": [ - "MyAwesomeFunctionCWLogPermission" - ] - }, - "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionEBRule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionEBSchedule": { "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ + "ScheduleExpression": "rate(1 minute)", + "Targets": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBScheduleLambdaTarget" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBSchedulePermission": { "Condition": "MyCondition", "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "MyAwesomeFunctionRole", + "MyAwesomeFunctionEBSchedule", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyAwesomeFunctionCWEvent": { - "Type": "AWS::Events::Rule", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionIoTRule": { "Condition": "MyCondition", "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "Id": "MyAwesomeFunctionCWEventLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" + "TopicRulePayload": { + "Actions": [ + { + "Lambda": { + "FunctionArn": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } } - } - ] - } + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, + "Sql": "SELECT * FROM 'topic/test'" + } + }, + "Type": "AWS::IoT::TopicRule" }, - "MyAwesomeFunctionEBRule": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionIoTRulePermission": { "Condition": "MyCondition", "Properties": { - "EventPattern": { - "detail": { - "state": [ - "launched" - ] - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Targets": [ - { - "Id": "MyAwesomeFunctionEBRuleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + { + "RuleName": { + "Ref": "MyAwesomeFunctionIoTRule" + } } - } - ] - } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "MyAwesomeFunctionKinesisStream": { "Condition": "MyCondition", "Properties": { + "BatchSize": 100, + "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", "FunctionName": { - "Ref": "MyAwesomeFunction" - } - } - }, - "Notifications": { - "Condition": "MyCondition", - "Type": "AWS::SNS::Topic" - }, - "MyAwesomeFunctionEBSchedulePermission": { - "Type": "AWS::Lambda::Permission", + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionNotificationTopic": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { + "Endpoint": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionEBSchedule", - "Arn" - ] + }, + "Protocol": "lambda", + "TopicArn": { + "Ref": "Notifications" } - } - }, - "FunctionOneImageBucketPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::SNS::Subscription" + }, + "MyAwesomeFunctionNotificationTopicPermission": { + "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, "FunctionName": { - "Ref": "FunctionOne" + "Ref": "MyAwesomeFunctionAliasLive" }, - "Principal": "s3.amazonaws.com" - } + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" }, - "FunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyAwesomeFunctionRole": { + "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -385,84 +487,40 @@ ] } } - ] - } - } - }, - "FunctionOne": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "FunctionOneRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "Images": { - "Type": "AWS::S3::Bucket", + "MyAwesomeFunctionS3TriggerPermission": { + "Condition": "MyCondition", "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Fn::If": [ - "MyCondition", - { - "Function": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Event": "s3:ObjectCreated:*" - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - { - "Function": { - "Fn::GetAtt": [ - "FunctionOne", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Tags": [ - { - "Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission", - "Value": { - "Fn::If": [ - "MyCondition", - { - "Ref": "MyAwesomeFunctionS3TriggerPermission" - }, - "no dependency" - ] - } - } - ] - }, - "DependsOn": [ - "FunctionOneImageBucketPermission" - ] + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionSNSTopicWithSQSSubscription": { - "Type": "AWS::SNS::Subscription", + "Condition": "MyCondition", "Properties": { "Endpoint": { "Fn::GetAtt": [ @@ -475,117 +533,32 @@ "Ref": "Notifications" } }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionSNSTopicWithSQSSubscriptionQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", - "Properties": { - "Queues": [ - { - "Ref": "Queue" - } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - }, - "Condition": "MyCondition" + "Type": "AWS::SNS::Subscription" }, "MyAwesomeFunctionSNSTopicWithSQSSubscriptionEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", + "Condition": "MyCondition", "Properties": { "BatchSize": 10, "Enabled": true, - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, "EventSourceArn": { "Fn::GetAtt": [ "Queue", "Arn" ] - } - }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue": { - "Condition": "MyCondition", - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, + }, "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - } - }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscription": { - "Type": "AWS::SNS::Subscription", - "Properties": { - "Endpoint": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" } }, - "Condition": "MyCondition" + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "MyAwesomeFunctionSNSTopicWithSQSSubscriptionQueuePolicy": { + "Condition": "MyCondition", "Properties": { - "Queues": [ - { - "Ref": "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - }, - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -593,16 +566,43 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + } } - ] + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "Queue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "MyAwesomeFunctionVersion640128d35d": { + "Condition": "MyCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MyAwesomeFunction" } }, - "Condition": "MyCondition" + "Type": "AWS::Lambda::Version" + }, + "Notifications": { + "Condition": "MyCondition", + "Type": "AWS::SNS::Topic" }, "Queue": { - "Type": "AWS::SQS::Queue", - "Condition": "MyCondition" + "Condition": "MyCondition", + "Type": "AWS::SQS::Queue" } } } diff --git a/tests/translator/output/aws-us-gov/function_managed_inline_policy.json b/tests/translator/output/aws-us-gov/function_managed_inline_policy.json index ffbf7809d2..5982356072 100644 --- a/tests/translator/output/aws-us-gov/function_managed_inline_policy.json +++ b/tests/translator/output/aws-us-gov/function_managed_inline_policy.json @@ -1,85 +1,85 @@ { "Parameters": { "SomeManagedPolicyArn": { - "Default": "arn:aws:iam::aws:policy/OtherPolicy", + "Default": "arn:aws:iam::aws:policy/OtherPolicy", "Type": "String" } - }, + }, "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", { "Ref": "SomeManagedPolicyArn" - }, + }, "arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { - "PolicyName": "FunctionRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionRolePolicy0" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_alias.json b/tests/translator/output/aws-us-gov/function_with_alias.json index aae104be56..5ef4d06179 100644 --- a/tests/translator/output/aws-us-gov/function_with_alias.json +++ b/tests/translator/output/aws-us-gov/function_with_alias.json @@ -1,82 +1,82 @@ { "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_alias_and_code_sha256.json b/tests/translator/output/aws-us-gov/function_with_alias_and_code_sha256.json index 94c25d971b..1862f8b671 100644 --- a/tests/translator/output/aws-us-gov/function_with_alias_and_code_sha256.json +++ b/tests/translator/output/aws-us-gov/function_with_alias_and_code_sha256.json @@ -1,89 +1,89 @@ { - "Parameters": { - "AutoPublishCodeSha256": { - "Type": "String", - "Description": "Sha256 to uniquely identify creation of the lambda", - "Default": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" - } - }, - "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Parameters": { + "AutoPublishCodeSha256": { + "Default": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b", + "Description": "Sha256 to uniquely identify creation of the lambda", + "Type": "String" + } + }, + "Resources": { + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] - } - }, - "MinimalFunctionVersion6b86b273ff": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion6b86b273ff", - "Version" - ] - } - } + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion6b86b273ff", + "Version" + ] + }, + "Name": "live" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion6b86b273ff": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json b/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json index 99ccfc0b33..35a2609b22 100644 --- a/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json +++ b/tests/translator/output/aws-us-gov/function_with_alias_and_event_sources.json @@ -1,179 +1,332 @@ { "Parameters": { "MyStageName": { - "Default": "beta", + "Default": "beta", "Type": "String" } - }, + }, "Resources": { + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": "MyGetApi", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "GetHtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "LambdaFunction": { + "Ref": "MyAwesomeFunction" + } + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Images": { + "DependsOn": [ + "MyAwesomeFunctionS3TriggerPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } + ] + } + }, + "Type": "AWS::S3::Bucket" + }, + "MyAwesomeFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyAwesomeFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyAwesomeFunctionAliasLive": { - "Type": "AWS::Lambda::Alias", "Properties": { + "FunctionName": { + "Ref": "MyAwesomeFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MyAwesomeFunctionVersion640128d35d", + "MyAwesomeFunctionVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "MyAwesomeFunction" - }, + }, "Name": "Live" - } - }, - "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Alias" + }, + "MyAwesomeFunctionCWEvent": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionCWEventLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionCWEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { - "Ref": "Notifications" + "Fn::GetAtt": [ + "MyAwesomeFunctionCWEvent", + "Arn" + ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentd696835fbb" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionCWLog": { + "DependsOn": [ + "MyAwesomeFunctionCWLogPermission" + ], "Properties": { - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "MyAwesomeFunctionCWEventPermission": { - "Type": "AWS::Lambda::Permission", + "DestinationArn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "FilterPattern": "My pattern", + "LogGroupName": "MyLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" + }, + "MyAwesomeFunctionCWLogPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "logs.amazonaws.com", "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionCWEvent", - "Arn" + "Fn::Sub": [ + "arn:aws-us-gov:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", + { + "__LogGroupName__": "MyLogGroup" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionDDBStream": { + "Properties": { + "BatchSize": 200, + "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionEBRule": { + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "launched" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBRuleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" }, "MyAwesomeFunctionEBRulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ "MyAwesomeFunctionEBRule", "Arn" ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionEBSchedule": { + "Properties": { + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBSchedulePermission": { "Properties": { - "BatchSize": 200, - "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "LATEST" - } + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionEBSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionIoTRule": { - "Type": "AWS::IoT::TopicRule", + "MyAwesomeFunctionExplicitApiPermissionStage": { "Properties": { - "TopicRulePayload": { - "AwsIotSqlVersion": "beta", - "Actions": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Lambda": { - "FunctionArn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } + "__ApiId__": { + "Ref": "GetHtmlApi" + }, + "__Stage__": "*" } - ], - "RuleDisabled": false, - "Sql": "SELECT * FROM 'topic/test'" + ] } - } - }, - "MyAwesomeFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 100, - "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "TRIM_HORIZON" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyAwesomeFunctionImplicitApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiDeploymentd696835fbb": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionIoTRule": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: d696835fbb61a45adb53a4391054f7f7404dfb2c", - "StageName": "Stage" - } - }, + "TopicRulePayload": { + "Actions": [ + { + "Lambda": { + "FunctionArn": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } + } + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, + "Sql": "SELECT * FROM 'topic/test'" + } + }, + "Type": "AWS::IoT::TopicRule" + }, "MyAwesomeFunctionIoTRulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", { "RuleName": { "Ref": "MyAwesomeFunctionIoTRule" @@ -181,312 +334,159 @@ } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionKinesisStream": { + "Properties": { + "BatchSize": 100, + "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } - }, - "MyAwesomeFunctionS3TriggerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Principal": "s3.amazonaws.com" - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": "MyGetApi" - } + }, + "Type": "AWS::SNS::Subscription" }, - "MyAwesomeFunctionCWLogPermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionNotificationTopicPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "sns.amazonaws.com", "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", - { - "__LogGroupName__": "MyLogGroup" - } - ] + "Ref": "Notifications" } - } - }, - "MyAwesomeFunctionEBSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "MyAwesomeFunctionEBScheduleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } - }, - "MyAwesomeFunctionCWLog": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "FilterPattern": "My pattern", - "LogGroupName": "MyLogGroup" - }, - "DependsOn": [ - "MyAwesomeFunctionCWLogPermission" - ] - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyAwesomeFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyAwesomeFunctionCWEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "Id": "MyAwesomeFunctionCWEventLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyAwesomeFunctionEBRule": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionS3TriggerPermission": { "Properties": { - "EventPattern": { - "detail": { - "state": [ - "launched" - ] - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Targets": [ - { - "Id": "MyAwesomeFunctionEBRuleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MyAwesomeFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "Notifications": { + "Type": "AWS::SNS::Topic" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyAwesomeFunctionAliasLive}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "Notifications": { - "Type": "AWS::SNS::Topic" - }, - "MyAwesomeFunctionEBSchedulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionEBSchedule", - "Arn" - ] - } - } - }, - "Images": { - "Type": "AWS::S3::Bucket", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentd696835fbb": { "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Event": "s3:ObjectCreated:*" - } - ] - } - }, - "DependsOn": [ - "MyAwesomeFunctionS3TriggerPermission" - ] - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", + "Description": "RestApi deployment id: d696835fbb61a45adb53a4391054f7f7404dfb2c", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, + "Ref": "ServerlessRestApiDeploymentd696835fbb" + }, "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "LambdaFunction": { - "Ref": "MyAwesomeFunction" - } - }, - "StageName": { - "Ref": "MyStageName" - } - } - }, - "MyAwesomeFunctionExplicitApiPermissionStage": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "GetHtmlApi" - } - } - ] - } - } + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_alias_intrinsics.json b/tests/translator/output/aws-us-gov/function_with_alias_intrinsics.json index 6844f0abb6..cca13a2547 100644 --- a/tests/translator/output/aws-us-gov/function_with_alias_intrinsics.json +++ b/tests/translator/output/aws-us-gov/function_with_alias_intrinsics.json @@ -1,87 +1,87 @@ { "Parameters": { "AliasName": { - "Default": "live", + "Default": "live", "Type": "String" } - }, + }, "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_amq.json b/tests/translator/output/aws-us-gov/function_with_amq.json index a8a471c860..4efe9510ac 100644 --- a/tests/translator/output/aws-us-gov/function_with_amq.json +++ b/tests/translator/output/aws-us-gov/function_with_amq.json @@ -1,7 +1,6 @@ { "Resources": { "MQFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,30 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MQFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,14 +56,14 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", "PolicyDocument": { "Statement": [ { @@ -65,7 +81,8 @@ "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" } ] - } + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" } ], "Tags": [ @@ -74,25 +91,8 @@ "Value": "SAM" } ] - } - }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_amq_kms.json b/tests/translator/output/aws-us-gov/function_with_amq_kms.json index 37b991a497..72930e0804 100644 --- a/tests/translator/output/aws-us-gov/function_with_amq_kms.json +++ b/tests/translator/output/aws-us-gov/function_with_amq_kms.json @@ -1,105 +1,105 @@ { - "Resources": { - "MQFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "queues.zip" - }, - "Handler": "queue.mq_handler", - "Role": { - "Fn::GetAtt": [ - "MQFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Resources": { + "MQFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "queues.zip" + }, + "Handler": "queue.mq_handler", + "Role": { + "Fn::GetAtt": [ + "MQFunctionRole", + "Arn" ] - } + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MQFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MQFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "mq:DescribeBroker" - ], - "Effect": "Allow", - "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" - } - } + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "mq:DescribeBroker" + ], + "Effect": "Allow", + "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" + }, + { + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" + } + } + ] + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" + } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ] - } - } + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_architectures.json b/tests/translator/output/aws-us-gov/function_with_architectures.json index b4069dad52..1745a15821 100644 --- a/tests/translator/output/aws-us-gov/function_with_architectures.json +++ b/tests/translator/output/aws-us-gov/function_with_architectures.json @@ -3,8 +3,10 @@ "Parameters": {}, "Resources": { "TestFunc": { - "Type": "AWS::Lambda::Function", "Properties": { + "Architectures": [ + "arm64" + ], "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" @@ -19,23 +21,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ], - "Architectures": [ - "arm64" - ] - } + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "TestFuncRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -48,7 +46,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -59,7 +58,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_auth_mechanism_for_self_managed_kafka.json b/tests/translator/output/aws-us-gov/function_with_auth_mechanism_for_self_managed_kafka.json index dd15eecf39..790334257b 100644 --- a/tests/translator/output/aws-us-gov/function_with_auth_mechanism_for_self_managed_kafka.json +++ b/tests/translator/output/aws-us-gov/function_with_auth_mechanism_for_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +65,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -70,32 +94,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_condition.json b/tests/translator/output/aws-us-gov/function_with_condition.json index 55fc68469b..275773abd3 100644 --- a/tests/translator/output/aws-us-gov/function_with_condition.json +++ b/tests/translator/output/aws-us-gov/function_with_condition.json @@ -2,66 +2,66 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "test", + "test", "test" ] } - }, + }, "Resources": { "ConditionFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "TestCondition", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ConditionFunctionRole", + "ConditionFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "TestCondition" - }, + }, + "Type": "AWS::Lambda::Function" + }, "ConditionFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "TestCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "TestCondition" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy.json b/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy.json index e2a0e8c5f7..2f6e7c9dd4 100644 --- a/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy.json +++ b/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,12 +22,34 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", { @@ -54,24 +69,9 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy_and_ref_no_value.json b/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy_and_ref_no_value.json index da893a16c6..3e59691e34 100644 --- a/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy_and_ref_no_value.json +++ b/tests/translator/output/aws-us-gov/function_with_conditional_managed_policy_and_ref_no_value.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,12 +22,34 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", { @@ -54,24 +69,9 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_conditional_policy_template.json b/tests/translator/output/aws-us-gov/function_with_conditional_policy_template.json index 18e2f72162..30efe7be75 100644 --- a/tests/translator/output/aws-us-gov/function_with_conditional_policy_template.json +++ b/tests/translator/output/aws-us-gov/function_with_conditional_policy_template.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,33 +22,49 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { "Fn::If": [ "DummyCondition", { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${secretArn}", @@ -63,14 +72,13 @@ "secretArn": "Dummy Secret Arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" }, { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { @@ -80,10 +88,6 @@ "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" ], - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" - }, - "Effect": "Allow", "Condition": { "StringEquals": { "secretsmanager:resource/AllowRotationLambdaArn": { @@ -95,38 +99,34 @@ ] } } + }, + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" } }, { "Action": [ "secretsmanager:GetRandomPassword" ], - "Resource": "*", - "Effect": "Allow" + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" } ] } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_conditional_policy_template_and_ref_no_value.json b/tests/translator/output/aws-us-gov/function_with_conditional_policy_template_and_ref_no_value.json index 08c9629f11..48d250f83a 100644 --- a/tests/translator/output/aws-us-gov/function_with_conditional_policy_template_and_ref_no_value.json +++ b/tests/translator/output/aws-us-gov/function_with_conditional_policy_template_and_ref_no_value.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,33 +22,49 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { "Fn::If": [ "DummyCondition", { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${secretArn}", @@ -63,11 +72,11 @@ "secretArn": "Dummy Secret Arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" }, { "Ref": "AWS::NoValue" @@ -75,23 +84,14 @@ ] } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json index f601b9622d..50c53e6253 100644 --- a/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json +++ b/tests/translator/output/aws-us-gov/function_with_custom_codedeploy_deployment_preference.json @@ -1,906 +1,906 @@ { - "Parameters": { - "Deployment": { - "Default": "AllAtOnce", - "Type": "String" - }, - "Custom": { - "Default": "CustomDeployment", - "Type": "String" - }, - "Stage": { - "Default": "beta", - "Type": "String" - } - }, "Conditions": { "MyCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Mappings": { "DeploymentPreferenceMap": { "beta": { "DeploymentPreference": "CustomDeployment" - }, + }, "prod": { "DeploymentPreference": "AllAtOnce" } } - }, + }, + "Parameters": { + "Custom": { + "Default": "CustomDeployment", + "Type": "String" + }, + "Deployment": { + "Default": "AllAtOnce", + "Type": "String" + }, + "Stage": { + "Default": "beta", + "Type": "String" + } + }, "Resources": { - "NormalWithRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "NormalWithRefDeploymentGroup" + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithCondition": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "CustomWithConditionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithCondition2": { "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "CustomWithCondition2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithCondition2Aliaslive": { + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" + }, "FunctionVersion": { "Fn::GetAtt": [ - "NormalWithRefVersion640128d35d", + "CustomWithCondition2Version640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "NormalWithRef" - }, + }, "Name": "live" - } - }, - "CustomWithFindInMapVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithFindInMap" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithCondition2DeploymentGroup" + } } } - }, + }, "CustomWithCondition2DeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "CustomDeployment" ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "CustomWithFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithFindInMapDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "CustomWithFindInMapVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "CustomWithFindInMap" - }, - "Name": "live" - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "CodeDeployServiceRole", "Arn" ] - }, - "Runtime": "python2.7", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithCondition2Role": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithSubAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithSubDeploymentGroup" - } + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithCondition2Version640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithConditionAliaslive": { "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + }, "FunctionVersion": { "Fn::GetAtt": [ - "CustomWithSubVersion640128d35d", + "CustomWithConditionVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "CustomWithSub" - }, + }, "Name": "live" - } - }, - "NormalWithSub": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "NormalWithSubRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithConditionDeploymentGroup" } - ] - } - }, - "CustomWithConditionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithCondition" } } - }, - "CustomWithSubDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithConditionDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + "TestDeploymentConfiguration", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": "CustomDeployment" - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "CustomWithCondition2Version640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithCondition2" - } - } - }, - "CustomWithCondition": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithConditionRole": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "CustomWithConditionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithSub": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithConditionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + } + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithFindInMap": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "CustomWithSubRole", + "CustomWithFindInMapRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "NormalWithRefVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithFindInMapAliaslive": { "Properties": { "FunctionName": { - "Ref": "NormalWithRef" + "Ref": "CustomWithFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithFindInMapVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithFindInMapDeploymentGroup" + } } } - }, - "NormalWithSubDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithFindInMapDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": "CustomDeployment", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithFindInMapRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithFindInMapVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithFindInMap" } - } - }, - "NormalWithRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithSub": { "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CustomWithSubRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "NormalWithSubAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "NormalWithSubDeploymentGroup" + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithSubAliaslive": { "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" + }, "FunctionVersion": { "Fn::GetAtt": [ - "NormalWithSubVersion640128d35d", + "CustomWithSubVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "NormalWithSub" - }, + }, "Name": "live" - } - }, - "CustomWithSubVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithSub" - } - } - }, - "CustomWithSubRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "CustomWithConditionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithSubDeploymentGroup" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] } } - }, - "CustomWithConditionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithSubDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": "CustomDeployment" + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::If": [ - "MyCondition", - "TestDeploymentConfiguration", - { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithSubRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" } - } - }, - "CustomWithFindInMap": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunction": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "CustomWithFindInMapRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "NormalWithSubVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { "Properties": { "FunctionName": { - "Ref": "NormalWithSub" - } - } - }, - "CustomWithConditionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { - "Ref": "CustomWithConditionDeploymentGroup" + "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "CustomWithConditionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "CustomWithCondition" - }, - "Name": "live" - } - }, - "CustomWithFindInMapRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "NormalWithRef": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "NormalWithRefRole", + "NormalWithRefRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithCondition2": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "NormalWithRefAliaslive": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { + "FunctionName": { + "Ref": "NormalWithRef" + }, + "FunctionVersion": { "Fn::GetAtt": [ - "CustomWithCondition2Role", - "Arn" + "NormalWithRefVersion640128d35d", + "Version" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithRefDeploymentGroup" } - ] + } } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "NormalWithRefDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": "TestDeploymentConfiguration", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, "NormalWithRefRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "CustomWithCondition2Aliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithCondition2DeploymentGroup" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "NormalWithRefVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "NormalWithRef" } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "NormalWithSub": { "Properties": { - "FunctionVersion": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CustomWithCondition2Version640128d35d", - "Version" + "NormalWithSubRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "CustomWithCondition2" - }, - "Name": "live" - } - }, - "NormalWithSubRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "NormalWithSubAliaslive": { "Properties": { "FunctionName": { - "Ref": "MinimalFunction" + "Ref": "NormalWithSub" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithSubVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithSubDeploymentGroup" + } } } - }, - "CustomWithFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "NormalWithSubDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": "CustomDeployment", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, - "CustomWithCondition2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "NormalWithSubRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "NormalWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "NormalWithSub" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json index b91a7f0ffc..ed74f9d4ff 100644 --- a/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json +++ b/tests/translator/output/aws-us-gov/function_with_custom_conditional_codedeploy_deployment_preference.json @@ -1,199 +1,199 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": { - "EnvType": { - "Default": "dev", - "Type": "String" - } - }, + "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "IsDevEnv2": { + "IsDevEnv": { "Fn::Equals": [ { "Ref": "EnvType" - }, - "prod" + }, + "dev" ] - }, - "IsDevEnv": { + }, + "IsDevEnv2": { "Fn::Equals": [ { "Ref": "EnvType" - }, - "dev" + }, + "prod" ] } - }, + }, + "Parameters": { + "EnvType": { + "Default": "dev", + "Type": "String" + } + }, "Resources": { - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "HelloWorldFunction": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "HelloWorldFunctionVersionfb53d5c2e6", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "HelloWorldFunctionDeploymentGroup" + } } } - }, + }, "HelloWorldFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::If": [ - "IsDevEnv", + "IsDevEnv", { "Fn::If": [ - "IsDevEnv2", + "IsDevEnv2", { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "TestCustomDeploymentConfig" ] - }, + }, { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Canary10Percent15Minutes" } ] } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "HelloWorldFunctionVersionfb53d5c2e6": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "HelloWorldFunction" - } - } - }, - "HelloWorldFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "HelloWorldFunctionDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "HelloWorldFunctionVersionfb53d5c2e6", - "Version" - ] - }, - "FunctionName": { - "Ref": "HelloWorldFunction" - }, - "Name": "live" - } - }, - "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "HelloWorldFunctionRole", + "CodeDeployServiceRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "HelloWorldFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "HelloWorldFunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json b/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json index 68a5386069..e5394d7f4d 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_and_custom_role.json @@ -1,270 +1,270 @@ { "Resources": { - "FunctionWithRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "DeploymentRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "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", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithRole": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "DeploymentRole", + "Arn" ] - } - } - }, - "FunctionWithRoleVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithRoleAliaslive": { "Properties": { "FunctionName": { "Ref": "FunctionWithRole" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FunctionWithRoleVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FunctionWithRoleDeploymentGroup" + } } } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "FunctionWithRoleDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FunctionWithRoleVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FunctionWithRole" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "FunctionWithRoleDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "MinimalFunctionDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } - }, - "FunctionWithRoleAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FunctionWithRoleDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionWithRoleVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "FunctionWithRole" - }, - "Name": "live" - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json index 8300aab2f2..eb7425594f 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_with_passthrough.json @@ -8,66 +8,9 @@ } }, "Resources": { - "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "Condition1" - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "DeploymentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -76,90 +19,68 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" ] - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "DeploymentRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { "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" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -172,9 +93,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -184,34 +102,62 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "MinimalFunctionRole": { "Properties": { - "ComputePlatform": "Lambda" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunctionVersion640128d35d": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "OtherFunctionRole", @@ -221,39 +167,27 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + "OtherFunctionAliaslive": { + "Condition": "Condition1", "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] }, - "FunctionName": { - "Ref": "MinimalFunction" - }, "Name": "live" - } - }, - "OtherFunctionAliaslive": { + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -264,20 +198,86 @@ "Ref": "OtherFunctionDeploymentGroup" } } - }, + } + }, + "OtherFunctionDeploymentGroup": { "Condition": "Condition1", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", - "Version" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } ] }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "OtherFunctionRole": { + "Condition": "Condition1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "OtherFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "OtherFunction" - }, - "Name": "live" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json index ad07002d04..dba8197893 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_no_service_role_without_passthrough.json @@ -8,65 +8,9 @@ } }, "Resources": { - "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "DeploymentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -75,90 +19,68 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" ] - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "DeploymentRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { "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" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -171,9 +93,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -183,34 +102,62 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "MinimalFunctionRole": { "Properties": { - "ComputePlatform": "Lambda" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunctionVersion640128d35d": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "OtherFunctionRole", @@ -220,39 +167,27 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + "OtherFunctionAliaslive": { + "Condition": "Condition1", "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] }, - "FunctionName": { - "Ref": "MinimalFunction" - }, "Name": "live" - } - }, - "OtherFunctionAliaslive": { + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -263,20 +198,85 @@ "Ref": "OtherFunctionDeploymentGroup" } } + } + }, + "OtherFunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + } }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "OtherFunctionRole": { "Condition": "Condition1", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", - "Version" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "OtherFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "OtherFunction" - }, - "Name": "live" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference.json index 3b6868a1ed..92980d2e2b 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference.json @@ -4,192 +4,192 @@ "Fn::Equals": [ { "Ref": "EnableAliasProvisionedConcurrency" - }, + }, true ] } - }, + }, "Parameters": { "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, + ], + "Default": true, + "Type": "String" + }, "FnName": { "Type": "String" - }, + }, "ProvisionedConcurrency": { - "Default": 10, + "Default": 10, "Type": "String" } - }, + }, "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" } + }, + { + "Ref": "AWS::NoValue" } ] } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "Name": "live", - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - }, - { - "Ref": "AWS::NoValue" } - ] + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_alarms_intrinsic_if.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_alarms_intrinsic_if.json index b156bf3184..78fd0079b2 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_alarms_intrinsic_if.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_alarms_intrinsic_if.json @@ -8,8 +8,31 @@ } }, "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -29,18 +52,22 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "MinimalFunctionAliaslive": { "Properties": { "FunctionName": { "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -51,88 +78,14 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "AlarmConfiguration": { "Fn::If": [ "MyCondition", { - "Enabled": true, "Alarms": [ { "Name": "Alarm1" @@ -143,10 +96,10 @@ { "Name": "Alarm3" } - ] + ], + "Enabled": true }, { - "Enabled": true, "Alarms": [ { "Name": "Alarm1" @@ -154,7 +107,8 @@ { "Name": "Alarm5" } - ] + ], + "Enabled": true } ] }, @@ -178,8 +132,8 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, "ServiceRoleArn": { "Fn::GetAtt": [ @@ -187,7 +141,53 @@ "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_all_parameters.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_all_parameters.json index 2eb18aee3a..2c27a740bb 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_all_parameters.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_all_parameters.json @@ -1,138 +1,121 @@ { "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery1Minute" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] }, @@ -142,162 +125,179 @@ "DeploymentSuccess", "DeploymentFailure" ], + "TriggerName": "TestTrigger", "TriggerTargetArn": { "Ref": "MySNSTopic" - }, - "TriggerName": "TestTrigger" + } } ] - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", + "MySanityTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MySNSTopic": { - "Type": "AWS::SNS::Topic" + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json index 385a1f49fa..67afa7ad57 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_with_passthrough.json @@ -17,12 +17,12 @@ }, "Parameters": { "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", "AllowedValues": [ true, false - ] + ], + "Default": true, + "Type": "String" }, "FnName": { "Type": "String" @@ -33,46 +33,10 @@ } }, "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { + "Condition": "FunctionCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -81,32 +45,27 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "Condition": "FunctionCondition" + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -116,56 +75,40 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition" + "Type": "AWS::Lambda::Function" }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { + "Condition": "FunctionCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" } + }, + { + "Ref": "AWS::NoValue" } ] } }, - "Condition": "FunctionCondition" - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionAliaslive": { "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -176,33 +119,90 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Condition": "FunctionCondition", "Properties": { - "Name": "live", - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Ref": "AWS::NoValue" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Condition": "FunctionCondition", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json index d69bc3b599..a3fafb5e54 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_condition_without_passthrough.json @@ -1,205 +1,205 @@ { - "Conditions": { - "AliasProvisionedConcurrencyEnabled": { - "Fn::Equals": [ - { - "Ref": "EnableAliasProvisionedConcurrency" - }, - true + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "AllowedValues": [ + true, + false + ], + "Default": true, + "Type": "String" + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "FunctionCondition": { - "Fn::Equals": [ - true, - true - ] - } + "Type": "AWS::IAM::Role" }, - "Parameters": { - "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", - "AllowedValues": [ - true, - false + "MinimalFunction": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] }, - "FnName": { - "Type": "String" - }, - "ProvisionedConcurrency": { - "Default": 10, - "Type": "String" - } + "Type": "AWS::Lambda::Function" }, - "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { + "MinimalFunctionAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" } } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + } + }, + "MinimalFunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "Condition": "FunctionCondition" - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Value": "SAM", - "Key": "lambda:createdBy" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, - "Condition": "FunctionCondition" + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "FunctionCondition" + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, - "Condition": "FunctionCondition", - "Properties": { - "Name": "live", - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - } - } - } + "Type": "AWS::CodeDeploy::Application" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json index 960cf3d85b..5b0020b075 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_from_parameters.json @@ -1,152 +1,135 @@ { "Parameters": { - "MyTrueParameter": { - "Default": "True", - "Type": "String" - }, "MyLowerFalseParameter": { "Default": "false", "Type": "String" }, + "MyTrueParameter": { + "Default": "True", + "Type": "String" + }, "MyUpperFalseParameter": { "Default": "False", "Type": "String" } }, "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery1Minute" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] }, @@ -156,162 +139,179 @@ "DeploymentSuccess", "DeploymentFailure" ], + "TriggerName": "TestTrigger", "TriggerTargetArn": { "Ref": "MySNSTopic" - }, - "TriggerName": "TestTrigger" + } } ] - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", + "MySanityTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MySNSTopic": { - "Type": "AWS::SNS::Topic" + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json index 2ad3524ecf..ec2df82f7d 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations.json @@ -1,486 +1,486 @@ { "Resources": { - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" ] - } - } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { - "Type": "AWS::Lambda::Alias", + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" } } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - }, - "Name": "livewithdeployment" } - }, + }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery2Minutes" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "MinimalFunctionWithMinimalDeploymentPreferenceRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { "Properties": { - "Code": { - "S3Bucket": "my-bucket", - "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", - "Role": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", - "Arn" + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Name": "livewithdeployment" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" } - ] - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" } } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, + }, "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Canary10Percent5Minutes" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } - } - }, - "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySanityTestFunction": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - }, - "Name": "livewithdeploymentwithhooksandalarms" - } - }, + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyValidationTestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json index d534f9d6f1..978bf4d76f 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json @@ -1,19 +1,9 @@ { "Conditions": { - "ServerlessCodeDeployCondition": { - "Fn::Or": [ - { - "Condition": "Condition2" - }, - { - "Condition": "Condition1" - } - ] - }, - "Condition3": { + "Condition1": { "Fn::Equals": [ true, - false + true ] }, "Condition2": { @@ -22,10 +12,20 @@ false ] }, - "Condition1": { + "Condition3": { "Fn::Equals": [ true, - true + false + ] + }, + "ServerlessCodeDeployCondition": { + "Fn::Or": [ + { + "Condition": "Condition2" + }, + { + "Condition": "Condition1" + } ] } }, @@ -36,38 +36,39 @@ } }, "Resources": { - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "CodeDeployServiceRole": { + "Condition": "ServerlessCodeDeployCondition", "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "Condition": "Condition2" + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -77,50 +78,41 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionAliaslive": { + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "FunctionName": { + "Ref": "MinimalFunction" }, - "Role": { + "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", - "Arn" + "MinimalFunctionVersion640128d35d", + "Version" ] }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] + "Name": "live" }, - "Condition": "Condition2" + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "Condition1", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -133,12 +125,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -148,30 +134,22 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "Condition1" - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionRole": { + "Condition": "Condition1", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,54 +158,79 @@ "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } }, - "Condition": "ServerlessCodeDeployCondition" + "Type": "AWS::Lambda::Version" }, - "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Condition": "Condition2", "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "ServiceRoleArn": { + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Canary10Percent5Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "Condition2" + "Type": "AWS::Lambda::Function" }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Condition": "Condition2", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, @@ -236,92 +239,59 @@ }, "DeploymentGroupName": { "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" } } - }, - "Condition": "Condition2", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - }, - "Name": "livewithdeploymentwithhooksandalarms" } }, - "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "Condition": "Condition2", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "AlarmConfiguration": { + "Alarms": [ { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Name": { + "Ref": "MyCloudWatchAlarm" } } + ], + "Enabled": true + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "ConfigName": "Linear10PercentEvery2Minutes" } ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -334,53 +304,83 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition3" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Condition": "Condition2", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeployment" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "Condition": "Condition2", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -397,23 +397,13 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery2Minutes" + "ConfigName": "Canary10Percent5Minutes" } ] }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, "ServiceRoleArn": { "Fn::GetAtt": [ @@ -422,23 +412,12 @@ ] } }, - "Condition": "Condition2" - }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -451,54 +430,50 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition2" + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" - } - } - }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { "Condition": "Condition2", + "DeletionPolicy": "Retain", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" - ] - }, "FunctionName": { "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - }, - "Name": "livewithdeployment" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition3", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MySanityTestFunctionRole", @@ -508,64 +483,51 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition3" - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - }, - "Condition": "ServerlessCodeDeployCondition" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "MySanityTestFunctionRole": { + "Condition": "Condition3", "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "Condition1" - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "Condition": "Condition1", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + "Type": "AWS::IAM::Role" }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyValidationTestFunctionRole", @@ -575,11 +537,49 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyValidationTestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessDeploymentApplication": { + "Condition": "ServerlessCodeDeployCondition", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json index aaf0230728..e1c908421e 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json @@ -21,24 +21,36 @@ }, "Parameters": { "MyFalseParameter": { - "Type": "String", - "Default": false + "Default": false, + "Type": "String" } }, "Resources": { - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", + "CodeDeployServiceRole": { "Properties": { - "ComparisonOperator": "GreaterThanThreshold", - "EvaluationPeriods": 1, - "MetricName": "MyMetric", - "Namespace": "AWS/EC2", - "Period": 300, - "Threshold": 10 - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Condition": "Condition1", "Properties": { "Code": { @@ -59,21 +71,24 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionAliaslive": { "Condition": "Condition1", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition1", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { @@ -83,26 +98,46 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionVersion": { + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "Condition1", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -115,7 +150,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -126,10 +162,20 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { "Condition": "Condition2", "Properties": { "Code": { @@ -139,7 +185,7 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] }, @@ -150,50 +196,89 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { "Condition": "Condition2", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition2", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" } } - }, + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { "Properties": { - "Name": "livewithdeployment", - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true }, - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -206,7 +291,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -217,10 +303,20 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithMinimalDeploymentPreference": { "Condition": "Condition2", "Properties": { "Code": { @@ -230,7 +326,7 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "MinimalFunctionWithMinimalDeploymentPreferenceRole", "Arn" ] }, @@ -241,56 +337,73 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { "Condition": "Condition2", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - } - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeployment" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition2", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" } } - }, + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { "Properties": { - "Name": "livewithdeploymentwithhooksandalarms", - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionVersion": { + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -303,7 +416,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -314,10 +428,31 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Condition": "Condition3", "Properties": { "Code": { @@ -338,14 +473,13 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "Condition3", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -358,7 +492,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -369,10 +504,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "my-bucket", @@ -392,13 +527,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -411,7 +545,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -422,149 +557,14 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", "Properties": { "ComputePlatform": "Lambda" - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] - } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery2Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Canary10Percent5Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "AlarmConfiguration": { - "Enabled": true, - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ] - }, - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery2Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json b/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json index 05b248c261..965b943ea5 100644 --- a/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json +++ b/tests/translator/output/aws-us-gov/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json @@ -1,649 +1,649 @@ { - "Mappings": { - "HelloWorldMap": { - "hello": { - "key1": true, - "key2": false - }, - "world": { - "key1": false, - "key2": true - } - } + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] }, - "Parameters": { - "FnName": { - "Type": "String" - }, - "ProvisionedConcurrency": { - "Type": "String", - "Default": 10 - }, - "EnableAliasProvisionedConcurrency": { - "Type": "String", - "AllowedValues": [ - true, - false - ], - "Default": true - }, - "DefaultTrueParam": { - "Type": "String", - "Default": "true" - }, - "DefaultFalseParam": { - "Type": "String", - "Default": "false" - }, - "HelloParam": { - "Type": "String", - "Default": "hello" - }, - "WorldParam": { - "Type": "String", - "Default": "world" - } + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Mappings": { + "HelloWorldMap": { + "hello": { + "key1": true, + "key2": false + }, + "world": { + "key1": false, + "key2": true + } + } + }, + "Parameters": { + "DefaultFalseParam": { + "Default": "false", + "Type": "String" }, - "Conditions": { - "AliasProvisionedConcurrencyEnabled": { - "Fn::Equals": [ - { - "Ref": "EnableAliasProvisionedConcurrency" - }, - true - ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - true - ] - } + "DefaultTrueParam": { + "Default": "true", + "Type": "String" + }, + "EnableAliasProvisionedConcurrency": { + "AllowedValues": [ + true, + false + ], + "Default": true, + "Type": "String" + }, + "FnName": { + "Type": "String" + }, + "HelloParam": { + "Default": "hello", + "Type": "String" }, - "Resources": { - "TrueRef": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "TrueRefRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + }, + "WorldParam": { + "Default": "world", + "Type": "String" + } + }, + "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "TrueRefVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "TrueRef" - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseFindInMap": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseFindInMapRole", + "Arn" + ] }, - "TrueRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "TrueRefDeploymentGroup" - } - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FalseFindInMapAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseFindInMapVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "TrueRef" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "TrueRefVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseFindInMapDeploymentGroup" + } + } + } + }, + "FalseFindInMapDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueRefRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "FalseRef": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FalseRefRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FalseFindInMapRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "FalseRefVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "FalseRef" - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseFindInMapVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + } + }, + "Type": "AWS::Lambda::Version" + }, + "FalseRef": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "FalseRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FalseRefDeploymentGroup" - } - } + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FalseRefAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseRefVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "FalseRef" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FalseRefVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseRefDeploymentGroup" + } + } + } + }, + "FalseRefDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FalseRefRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, - "TrueFindInMap": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "TrueFindInMapRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FalseRefRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "TrueFindInMapVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "TrueFindInMap" - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseRefVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" + }, + "TrueFindInMap": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "TrueFindInMapAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueFindInMapVersion640128d35d", + "Version" + ] }, - "TrueFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "TrueFindInMapDeploymentGroup" - } - } + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "TrueFindInMap" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "TrueFindInMapVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueFindInMapDeploymentGroup" + } + } + } + }, + "TrueFindInMapDeploymentGroup": { + "Condition": "FunctionCondition", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueFindInMapRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "FalseFindInMap": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FalseFindInMapRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "TrueFindInMapRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "FalseFindInMapVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "FalseFindInMap" - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TrueFindInMapVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + } + }, + "Type": "AWS::Lambda::Version" + }, + "TrueRef": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "FalseFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FalseFindInMapDeploymentGroup" - } - } - }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "FalseFindInMap" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FalseFindInMapVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - } + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueRefRole", + "Arn" + ] }, - "FalseFindInMapRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "TrueRefAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueRefVersion640128d35d", + "Version" + ] }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueRefDeploymentGroup" + } + } + } + }, + "TrueRefDeploymentGroup": { + "Condition": "FunctionCondition", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Condition": "FunctionCondition", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] }, - "FalseRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "TrueFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Condition": "FunctionCondition", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, - "FalseFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "TrueRefRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TrueRefVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" } + }, + "Type": "AWS::Lambda::Version" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_disabled_deployment_preference.json b/tests/translator/output/aws-us-gov/function_with_disabled_deployment_preference.json index 6057dd5f9c..3d229c8823 100644 --- a/tests/translator/output/aws-us-gov/function_with_disabled_deployment_preference.json +++ b/tests/translator/output/aws-us-gov/function_with_disabled_deployment_preference.json @@ -1,81 +1,81 @@ { "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_disabled_traffic_hook.json b/tests/translator/output/aws-us-gov/function_with_disabled_traffic_hook.json index f9a12a7c22..58326e9d1a 100644 --- a/tests/translator/output/aws-us-gov/function_with_disabled_traffic_hook.json +++ b/tests/translator/output/aws-us-gov/function_with_disabled_traffic_hook.json @@ -3,7 +3,6 @@ "Description": "Template with preference that does not require a new CodeDeploy Service Role", "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -20,59 +19,89 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionVersionfb53d5c2e6": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "FunctionAliaslive": { "Properties": { "FunctionName": { "Ref": "Function" - } - } - }, - "FunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FunctionVersionfb53d5c2e6", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "DeploymentGroupName": { - "Ref": "FunctionDeploymentGroup" - }, "BeforeAllowTrafficHook": { "Ref": "preTrafficHook" + }, + "DeploymentGroupName": { + "Ref": "FunctionDeploymentGroup" } } + } + }, + "FunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery1Minute" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/custom-codedeploy-servicerole" + } }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", "Properties": { - "Name": "live", "FunctionName": { "Ref": "Function" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionVersionfb53d5c2e6", - "Version" - ] } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" }, "preTrafficHook": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", "S3Key": "key" }, - "FunctionName": "CodeDeployHook_preTrafficHook", - "Handler": "hook.lambda_handler", - "Role": { - "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/lambda-role" - }, - "Runtime": "python3.7", - "Timeout": 5, "Environment": { "Variables": { "NewVersion": { @@ -80,27 +109,24 @@ } } }, + "FunctionName": "CodeDeployHook_preTrafficHook", + "Handler": "hook.lambda_handler", + "Role": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/lambda-role" + }, + "Runtime": "python3.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "preTrafficHookVersion5e9ab26520": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "preTrafficHook" - } - } + ], + "Timeout": 5 + }, + "Type": "AWS::Lambda::Function" }, "preTrafficHookAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { - "Name": "live", "FunctionName": { "Ref": "preTrafficHook" }, @@ -109,45 +135,19 @@ "preTrafficHookVersion5e9ab26520", "Version" ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "FunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "preTrafficHookVersion5e9ab26520": { + "DeletionPolicy": "Retain", "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery1Minute" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/custom-codedeploy-servicerole" + "FunctionName": { + "Ref": "preTrafficHook" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_dlq.json b/tests/translator/output/aws-us-gov/function_with_dlq.json index d72373ef24..8a0c590eb8 100644 --- a/tests/translator/output/aws-us-gov/function_with_dlq.json +++ b/tests/translator/output/aws-us-gov/function_with_dlq.json @@ -1,34 +1,34 @@ { "Resources": { - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "MySnsDlqLambdaFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DeadLetterConfig": { + "TargetArn": "arn" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MySnsDlqLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": "arn", - "Effect": "Allow" - } - ] - } - } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MySnsDlqLambdaFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -41,62 +41,45 @@ ] } } - ] - } - } - }, - "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": "arn", - "Effect": "Allow" + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": "arn" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "DeadLetterConfig": { + "TargetArn": "arn" + }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -104,43 +87,60 @@ "Arn" ] }, - "DeadLetterConfig": { - "TargetArn": "arn" - }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "MySqsDlqLambdaFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySnsDlqLambdaFunctionRole", - "Arn" - ] - }, - "DeadLetterConfig": { - "TargetArn": "arn" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Effect": "Allow", + "Resource": "arn" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" + } + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_ephemeral_storage.json b/tests/translator/output/aws-us-gov/function_with_ephemeral_storage.json index d634b0af05..abb72abf25 100644 --- a/tests/translator/output/aws-us-gov/function_with_ephemeral_storage.json +++ b/tests/translator/output/aws-us-gov/function_with_ephemeral_storage.json @@ -1,123 +1,123 @@ { + "Parameters": { + "EphemeralStorageSizeRef": { + "Type": "Number" + } + }, "Resources": { "FunctionWithIntrinsicRef": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + }, "EphemeralStorage": { "Size": { "Ref": "EphemeralStorageSizeRef" } - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithIntrinsicRefRole", + "FunctionWithIntrinsicRefRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionWithIntrinsicRefRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "EphemeralStorage": { - "Size": 1024 - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - } - }, - "Parameters": { - "EphemeralStorageSizeRef": { - "Type": "Number" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_bridge_rule_state.json b/tests/translator/output/aws-us-gov/function_with_event_bridge_rule_state.json index 66513b8452..3ccbb3ccd1 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_bridge_rule_state.json +++ b/tests/translator/output/aws-us-gov/function_with_event_bridge_rule_state.json @@ -1,118 +1,118 @@ { - "Resources": { - "TestBucket": { - "Type": "AWS::S3::Bucket", - "Properties": { - "BucketName": "test-bucket" - } - }, - "TestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return 'Hello from Lambda!';\n};\n" - }, - "FunctionName": "test-function", - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "TestFunctionRole", - "Arn" - ] + "Resources": { + "TestBucket": { + "Properties": { + "BucketName": "test-bucket" + }, + "Type": "AWS::S3::Bucket" }, - "Runtime": "nodejs16.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "TestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "TestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return 'Hello from Lambda!';\n};\n" + }, + "FunctionName": "test-function", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "TestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs16.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] - } - } - ] + }, + "Type": "AWS::Lambda::Function" }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "TestFunctionTestEventBridgeRule": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "source": [ - "aws.s3" - ], - "detail-type": [ - "Object Created" - ], - "detail": { - "bucket": { - "name": [ - "test-bucket" - ] + "TestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "object": { - "key": [ - { - "prefix": "/" - } - ] - } - } + "Type": "AWS::IAM::Role" }, - "State": "ENABLED", - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "TestFunction", - "Arn" - ] + "TestFunctionTestEventBridgeRule": { + "Properties": { + "EventPattern": { + "detail": { + "bucket": { + "name": [ + "test-bucket" + ] + }, + "object": { + "key": [ + { + "prefix": "/" + } + ] + } + }, + "detail-type": [ + "Object Created" + ], + "source": [ + "aws.s3" + ] + }, + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "TestFunction", + "Arn" + ] + }, + "Id": "TestFunctionTestEventBridgeRuleLambdaTarget" + } + ] }, - "Id": "TestFunctionTestEventBridgeRuleLambdaTarget" - } - ] - } - }, - "TestFunctionTestEventBridgeRulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "TestFunction" + "Type": "AWS::Events::Rule" }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "TestFunctionTestEventBridgeRule", - "Arn" - ] + "TestFunctionTestEventBridgeRulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TestFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "TestFunctionTestEventBridgeRule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" } - } } - } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_dest.json b/tests/translator/output/aws-us-gov/function_with_event_dest.json index 629685776d..9dcb479dfd 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_dest.json +++ b/tests/translator/output/aws-us-gov/function_with_event_dest.json @@ -1,369 +1,369 @@ { "Conditions": { - "TopicCreationEnabled": { - "Fn::Equals": [ - { - "Ref": "CreateSNSTopic" - }, - true - ] - }, "NOTQueueCreationDisabled2da03e5b6f": { "Fn::Not": [ { "Condition": "QueueCreationDisabled" } ] - }, + }, "QueueCreationDisabled": { "Fn::Equals": [ { "Ref": "UseExistingQueue" - }, + }, + true + ] + }, + "TopicCreationEnabled": { + "Fn::Equals": [ + { + "Ref": "CreateSNSTopic" + }, true ] } - }, + }, "Parameters": { - "UseExistingQueue": { - "Default": true, - "Type": "String", - "AllowedValues": [ - true, - false - ] - }, "CreateSNSTopic": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, + ], + "Default": true, + "Type": "String" + }, "SQSArn": { - "Default": "my-sqs-arn", + "Default": "my-sqs-arn", + "Type": "String" + }, + "UseExistingQueue": { + "AllowedValues": [ + true, + false + ], + "Default": true, "Type": "String" } - }, + }, "Resources": { - "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", + "DestinationLambda": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "DestinationLambdaRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DestinationLambdaRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", - { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - }, - "my-sqs-arn" - ] - }, - "Effect": "Allow" - } - ] - } - }, + ], + "Tags": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "sns:publish", - "Resource": { - "Fn::If": [ - "TopicCreationEnabled", - { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - }, - "SOME-SNS-ARN" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {}, - "Condition": "NOTQueueCreationDisabled2da03e5b6f" - }, - "SNSSubscription": { - "Type": "AWS::SNS::Subscription", + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunction2": { "Properties": { - "Endpoint": "example@example.com", - "Protocol": "email", - "TopicArn": { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - } - }, - "Condition": "TopicCreationEnabled" - }, - "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunction2EventInvokeConfig": { "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { - "OnSuccess": { - "Destination": { - "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", - { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - }, - "my-sqs-arn" - ] - } - }, "OnFailure": { + "Destination": "event-bus-arn" + }, + "OnSuccess": { "Destination": { - "Fn::If": [ - "TopicCreationEnabled", - { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - }, - "SOME-SNS-ARN" + "Fn::GetAtt": [ + "DestinationLambda", + "Arn" ] } } - }, + }, "FunctionName": { - "Ref": "MyTestFunction" - }, + "Ref": "MyTestFunction2" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - } - }, + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, "MyTestFunction2Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunction2EventInvokeConfigOnSuccessLambdaPolicy", "PolicyDocument": { "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "DestinationLambda", + "DestinationLambda", "Arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunction2EventInvokeConfigOnSuccessLambdaPolicy" + }, { - "PolicyName": "MyTestFunction2EventInvokeConfigOnFailureEventBridgePolicy", "PolicyDocument": { "Statement": [ { - "Action": "events:PutEvents", - "Resource": "event-bus-arn", - "Effect": "Allow" + "Action": "events:PutEvents", + "Effect": "Allow", + "Resource": "event-bus-arn" } ] - } + }, + "PolicyName": "MyTestFunction2EventInvokeConfigOnFailureEventBridgePolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "DestinationLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "DestinationLambdaRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunction2EventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunctionEventInvokeConfig": { "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { + "OnFailure": { + "Destination": { + "Fn::If": [ + "TopicCreationEnabled", + { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + }, + "SOME-SNS-ARN" + ] + } + }, "OnSuccess": { "Destination": { - "Fn::GetAtt": [ - "DestinationLambda", - "Arn" + "Fn::If": [ + "NOTQueueCreationDisabled2da03e5b6f", + { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + }, + "my-sqs-arn" ] } - }, - "OnFailure": { - "Destination": "event-bus-arn" } - }, + }, "FunctionName": { - "Ref": "MyTestFunction2" - }, + "Ref": "MyTestFunction" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - } - }, - "DestinationLambdaRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, + "MyTestFunctionEventInvokeConfigOnFailureTopic": { + "Condition": "TopicCreationEnabled", + "Properties": {}, + "Type": "AWS::SNS::Topic" + }, + "MyTestFunctionEventInvokeConfigOnSuccessQueue": { + "Condition": "NOTQueueCreationDisabled2da03e5b6f", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "MyTestFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyTestFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Effect": "Allow", + "Resource": { + "Fn::If": [ + "NOTQueueCreationDisabled2da03e5b6f", + { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + }, + "my-sqs-arn" + ] + } + } + ] + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:publish", + "Effect": "Allow", + "Resource": { + "Fn::If": [ + "TopicCreationEnabled", + { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + }, + "SOME-SNS-ARN" + ] + } + } + ] + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunctionEventInvokeConfigOnFailureTopic": { - "Type": "AWS::SNS::Topic", - "Properties": {}, - "Condition": "TopicCreationEnabled" + ] + }, + "Type": "AWS::IAM::Role" + }, + "SNSSubscription": { + "Condition": "TopicCreationEnabled", + "Properties": { + "Endpoint": "example@example.com", + "Protocol": "email", + "TopicArn": { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + } + }, + "Type": "AWS::SNS::Subscription" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json b/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json index 2849abc9a1..3a62adf80a 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json +++ b/tests/translator/output/aws-us-gov/function_with_event_dest_basic.json @@ -1,149 +1,149 @@ { "Parameters": { "SNSArn": { - "Default": "my-sns-arn", + "Default": "my-sns-arn", "Type": "String" } - }, + }, "Resources": { + "MyTestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MyTestFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MyTestFunctionVersiondaf9da458d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyTestFunctionEventInvokeConfig": { + "DependsOn": [ + "MyTestFunctionAliaslive" + ], + "Properties": { + "DestinationConfig": { + "OnFailure": { + "Destination": "my-sns-arn" + }, + "OnSuccess": { + "Destination": { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + } + } + }, + "FunctionName": { + "Ref": "MyTestFunction" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, + "Qualifier": "live" + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sns:publish", - "Resource": "my-sns-arn", - "Effect": "Allow" + "Action": "sns:publish", + "Effect": "Allow", + "Resource": "my-sns-arn" } ] - } + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", - "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, - "DestinationConfig": { - "OnSuccess": { - "Destination": { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - } - }, - "OnFailure": { - "Destination": "my-sns-arn" - } - }, - "FunctionName": { - "Ref": "MyTestFunction" - }, - "Qualifier": "live" - }, - "DependsOn": [ - "MyTestFunctionAliaslive" - ] - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MyTestFunctionVersiondaf9da458d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MyTestFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "MyTestFunctionVersiondaf9da458d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MyTestFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_dest_conditional.json b/tests/translator/output/aws-us-gov/function_with_event_dest_conditional.json index 32175aa064..2fa1e616bc 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_dest_conditional.json +++ b/tests/translator/output/aws-us-gov/function_with_event_dest_conditional.json @@ -1,266 +1,266 @@ { "Conditions": { + "FunctionCondition": { + "Fn::Equals": [ + true, + false + ] + }, "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6": { "Fn::And": [ { "Condition": { "Condition": "FunctionCondition" } - }, + }, { "Condition": { "Condition": "NOTQueueCreationDisabled2da03e5b6f" } } ] - }, - "QueueCreationDisabled": { + }, + "FunctionInlineEnabled": { "Fn::Equals": [ - { - "Ref": "UseExistingQueue" - }, - true + true, + false ] - }, + }, "NOTQueueCreationDisabled2da03e5b6f": { "Fn::Not": [ { "Condition": "QueueCreationDisabled" } ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - false - ] - }, - "FunctionInlineEnabled": { + }, + "QueueCreationDisabled": { "Fn::Equals": [ - true, - false + { + "Ref": "UseExistingQueue" + }, + true ] } - }, + }, "Parameters": { + "SQSArn": { + "Default": "my-sqs-arn", + "Type": "String" + }, "UseExistingQueue": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, - "SQSArn": { - "Default": "my-sqs-arn", + ], + "Default": true, "Type": "String" } - }, + }, "Resources": { + "DestinationLambda": { + "Condition": "FunctionInlineEnabled", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "DestinationLambdaRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "DestinationLambdaRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionInlineEnabled", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionInlineEnabled" - }, - "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {}, - "Condition": "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6" - }, + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunction": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + "Condition": "FunctionCondition", "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { - "OnSuccess": { + "OnFailure": { "Destination": { "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", + "FunctionInlineEnabled", { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "DestinationLambda", "Arn" ] - }, - "my-sqs-arn" + }, + "some-function-arn" ] } - }, - "OnFailure": { + }, + "OnSuccess": { "Destination": { "Fn::If": [ - "FunctionInlineEnabled", + "NOTQueueCreationDisabled2da03e5b6f", { "Fn::GetAtt": [ - "DestinationLambda", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, - "some-function-arn" + }, + "my-sqs-arn" ] } } - }, + }, "FunctionName": { "Ref": "MyTestFunction" - }, + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - }, - "Condition": "FunctionCondition" - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "Condition": "FunctionCondition" - }, - "DestinationLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "DestinationLambdaRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "Condition": "FunctionInlineEnabled" - }, + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, + "MyTestFunctionEventInvokeConfigOnSuccessQueue": { + "Condition": "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", + "NOTQueueCreationDisabled2da03e5b6f", { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, + }, "my-sqs-arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureLambdaPolicy", "PolicyDocument": { "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::If": [ - "FunctionInlineEnabled", + "FunctionInlineEnabled", { "Fn::GetAtt": [ - "DestinationLambda", + "DestinationLambda", "Arn" ] - }, + }, "some-function-arn" ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureLambdaPolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_filtering.json b/tests/translator/output/aws-us-gov/function_with_event_filtering.json index 6411fd3c79..9b652467d1 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_filtering.json +++ b/tests/translator/output/aws-us-gov/function_with_event_filtering.json @@ -1,19 +1,9 @@ { "Resources": { - "KinesisStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } - }, "DynamoDBTable": { "Type": "AWS::DynamoDB::Table" }, - "MySqsQueue": { - "Type": "AWS::SQS::Queue" - }, "FilteredEventsFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -33,101 +23,10 @@ "Value": "SAM" } ] - } - }, - "FilteredEventsFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Policies": [ - { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "ec2:CreateNetworkInterface", - "ec2:DescribeNetworkInterfaces", - "ec2:DeleteNetworkInterface", - "ec2:DescribeVpcs", - "ec2:DescribeSubnets", - "ec2:DescribeSecurityGroups" - ], - "Effect": "Allow", - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "SelfManagedKafkaExecutionRolePolicy" - }, - { - "PolicyName": "SamAutoGeneratedAMQPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "mq:DescribeBroker" - ], - "Effect": "Allow", - "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" - } - } - ] - } - } - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "FilteredEventsFunctionDynamoDBStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": { "Fn::GetAtt": [ @@ -135,21 +34,21 @@ "StreamArn" ] }, - "FunctionName": { - "Ref": "FilteredEventsFunction" - }, - "StartingPosition": "TRIM_HORIZON", "FilterCriteria": { "Filters": [ { "Pattern": "{ \"dynamodb\": { \"NewImage\": { \"value\": { \"S\": [\"test\"] } } } }" } ] - } - } + }, + "FunctionName": { + "Ref": "FilteredEventsFunction" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "FilteredEventsFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": { "Fn::GetAtt": [ @@ -157,10 +56,6 @@ "Arn" ] }, - "FunctionName": { - "Ref": "FilteredEventsFunction" - }, - "StartingPosition": "LATEST", "FilterCriteria": { "Filters": [ { @@ -170,59 +65,53 @@ "Pattern": "{\"name2\": \"value2\"}" } ] - } - } - }, - "FilteredEventsFunctionMySqsEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Fn::GetAtt": [ - "MySqsQueue", - "Arn" - ] }, "FunctionName": { "Ref": "FilteredEventsFunction" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMSKEvent": { + "Properties": { + "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMSKEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, "StartingPosition": "LATEST", "Topics": [ "MyDummyTestTopic" - ], + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMyKafkaEvent": { + "Properties": { "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMyKafkaEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, - "Topics": [ - "Topic1" - ], + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092" + ] + } + }, "SourceAccessConfigurations": [ { "Type": "SASL_SCRAM_512_AUTH", @@ -237,26 +126,22 @@ "URI": "security_group:sg-67890" } ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092" - ] - } - }, + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, @@ -268,15 +153,130 @@ "Type": "BASIC_AUTH", "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" } - ], + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMySqsEvent": { + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MySqsQueue", + "Arn" + ] + }, "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] + }, + "FunctionName": { + "Ref": "FilteredEventsFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "ec2:CreateNetworkInterface", + "ec2:DescribeNetworkInterfaces", + "ec2:DeleteNetworkInterface", + "ec2:DescribeVpcs", + "ec2:DescribeSubnets", + "ec2:DescribeSecurityGroups" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "SelfManagedKafkaExecutionRolePolicy" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "mq:DescribeBroker" + ], + "Effect": "Allow", + "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" + }, + { + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" + } + } + ] + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" + } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "KinesisStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "MySqsQueue": { + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_schedule_state.json b/tests/translator/output/aws-us-gov/function_with_event_schedule_state.json index a49503a4e0..219b60262b 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_schedule_state.json +++ b/tests/translator/output/aws-us-gov/function_with_event_schedule_state.json @@ -1,176 +1,176 @@ { - "Parameters": { - "ScheduleState": { - "Type": "String", - "Default": "Disabled" - } - }, - "Resources": { - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ScheduledFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Parameters": { + "ScheduleState": { + "Default": "Disabled", + "Type": "String" + } + }, + "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "ScheduledFunctionSchedule1": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": "Enabled", - "Targets": [ + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] - }, - "Id": "ScheduledFunctionSchedule1LambdaTarget" + } } - ] - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "ScheduledFunctionSchedule1Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule1", - "Arn" - ] + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule1": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": "Enabled", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule1LambdaTarget" } - } + ] }, - "ScheduledFunctionSchedule2": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": { - "Fn::Sub": "Enabled" - }, - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - }, - "Id": "ScheduledFunctionSchedule2LambdaTarget" - } + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule1Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule1", + "Arn" ] } }, - "ScheduledFunctionSchedule2Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule2", - "Arn" - ] + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionSchedule2": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": { + "Fn::Sub": "Enabled" + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule2LambdaTarget" } - } + ] }, - "ScheduledFunctionSchedule3": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": { - "Ref": "ScheduleState" - }, - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - }, - "Id": "ScheduledFunctionSchedule3LambdaTarget" - } + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule2Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule2", + "Arn" ] } }, - "ScheduledFunctionSchedule3Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule3", - "Arn" - ] + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionSchedule3": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": { + "Ref": "ScheduleState" + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule3LambdaTarget" } + ] + }, + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule3Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule3", + "Arn" + ] } - } + }, + "Type": "AWS::Lambda::Permission" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_event_source_mapping.json b/tests/translator/output/aws-us-gov/function_with_event_source_mapping.json index 554891d3fc..5364d48d41 100644 --- a/tests/translator/output/aws-us-gov/function_with_event_source_mapping.json +++ b/tests/translator/output/aws-us-gov/function_with_event_source_mapping.json @@ -3,60 +3,124 @@ "Parameters": { "MyBatchingWindowParam": { "Default": 45, - "Type": "Number", - "Description": "parameter for batching window in seconds" + "Description": "parameter for batching window in seconds", + "Type": "Number" } }, "Resources": { - "MySqsQueue": { - "Type": "AWS::SQS::Queue" - }, - "MySnsTopic": { - "Type": "AWS::SNS::Topic" - }, - "MyFunctionForBatchingExampleStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": 20, - "EventSourceArn": { - "Fn::GetAtt": [ - "KinesisStream", - "Arn" - ] - }, - "FunctionName": { - "Ref": "MyFunctionForBatchingExample" - }, - "StartingPosition": "LATEST" - } - }, "DynamoDBTable": { - "Type": "AWS::DynamoDB::Table", "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, "StreamSpecification": { "StreamViewType": "NEW_IMAGE" + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "KinesisStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "KinesisStream1": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "MyFunctionForBatchingExample": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "AttributeDefinitions": [ + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionForBatchingExampleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "AttributeName": "id", - "AttributeType": "S" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionForBatchingExampleDynamoDBStreamEvent": { + "Properties": { + "BatchSize": 100, + "BisectBatchOnFunctionError": true, + "DestinationConfig": { + "OnFailure": { + "Destination": { + "Fn::GetAtt": [ + "MySqsQueue", + "Arn" + ] + } } + }, + "EventSourceArn": { + "Fn::GetAtt": [ + "DynamoDBTable", + "StreamArn" + ] + }, + "FunctionName": { + "Ref": "MyFunctionForBatchingExample" + }, + "FunctionResponseTypes": [ + "ReportBatchItemFailures" ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } + "MaximumBatchingWindowInSeconds": { + "Ref": "MyBatchingWindowParam" + }, + "MaximumRecordAgeInSeconds": 86400, + "MaximumRetryAttempts": 100, + "ParallelizationFactor": 8, + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyFunctionForBatchingExampleRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", @@ -64,13 +128,13 @@ ], "Policies": [ { - "PolicyName": "MyFunctionForBatchingExampleRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -83,14 +147,13 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MyFunctionForBatchingExampleRolePolicy0" }, { - "PolicyName": "MyFunctionForBatchingExampleDynamoDBStreamEventSQSPolicy", "PolicyDocument": { "Statement": [ { @@ -104,116 +167,58 @@ } } ] - } + }, + "PolicyName": "MyFunctionForBatchingExampleDynamoDBStreamEventSQSPolicy" }, { - "PolicyDocument": { - "Statement": [ - { - "Action": "sns:publish", - "Effect": "Allow", - "Resource": { - "Ref": "MySnsTopic" - } - } - ] - }, - "PolicyName": "MyFunctionForBatchingExampleStreamEventSNSPolicy" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:publish", + "Effect": "Allow", + "Resource": { + "Ref": "MySnsTopic" + } + } + ] + }, + "PolicyName": "MyFunctionForBatchingExampleStreamEventSNSPolicy" } ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "KinesisStream1": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionForBatchingExampleDynamoDBStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyFunctionForBatchingExampleStream": { "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "MyBatchingWindowParam" + "EventSourceArn": { + "Fn::GetAtt": [ + "KinesisStream", + "Arn" + ] }, "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "MaximumRecordAgeInSeconds": 86400, - "BatchSize": 100, + "MaximumBatchingWindowInSeconds": 20, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEvent": { + "Properties": { "DestinationConfig": { "OnFailure": { "Destination": { - "Fn::GetAtt": [ - "MySqsQueue", - "Arn" - ] + "Ref": "MySnsTopic" } } }, - "EventSourceArn": { - "Fn::GetAtt": [ - "DynamoDBTable", - "StreamArn" - ] - }, - "StartingPosition": "TRIM_HORIZON", - "ParallelizationFactor": 8, - "MaximumRetryAttempts": 100, - "BisectBatchOnFunctionError": true, - "TumblingWindowInSeconds": 60, - "FunctionResponseTypes": ["ReportBatchItemFailures"] - } - }, - "MyFunctionForBatchingExample": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionForBatchingExampleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionForBatchingExampleStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "MyBatchingWindowParam" - }, "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -223,22 +228,15 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "StartingPosition": "LATEST", - "DestinationConfig": { - "OnFailure": { - "Destination": { - "Ref": "MySnsTopic" - } - } - } - } - }, - "MyFunctionForBatchingExampleStreamEventWithoutDestinationConfigType": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { "MaximumBatchingWindowInSeconds": { "Ref": "MyBatchingWindowParam" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEventWithEmptyDestinationConfig": { + "Properties": { "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -248,22 +246,22 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "StartingPosition": "LATEST", - "DestinationConfig": { - "OnFailure": { - "Destination": { - "Ref": "MySnsTopic" - } - } - } - } - }, - "MyFunctionForBatchingExampleStreamEventWithEmptyDestinationConfig": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { "MaximumBatchingWindowInSeconds": { "Ref": "MyBatchingWindowParam" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEventWithoutDestinationConfigType": { + "Properties": { + "DestinationConfig": { + "OnFailure": { + "Destination": { + "Ref": "MySnsTopic" + } + } + }, "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -273,14 +271,18 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, + "MaximumBatchingWindowInSeconds": { + "Ref": "MyBatchingWindowParam" + }, "StartingPosition": "LATEST" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "KinesisStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } + "MySnsTopic": { + "Type": "AWS::SNS::Topic" + }, + "MySqsQueue": { + "Type": "AWS::SQS::Queue" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_file_system_config.json b/tests/translator/output/aws-us-gov/function_with_file_system_config.json index 132a7e9094..2b235ee082 100644 --- a/tests/translator/output/aws-us-gov/function_with_file_system_config.json +++ b/tests/translator/output/aws-us-gov/function_with_file_system_config.json @@ -1,115 +1,115 @@ { + "Description": "SAM + Lambda + EFS", + "Parameters": { + "ExistingEfsFileSystem": { + "Type": "String" + }, + "SecurityGroupIds": { + "Description": "Security Group IDs that Lambda will use", + "Type": "List" + }, + "VpcSubnetIds": { + "Description": "VPC Subnet IDs that Lambda will use", + "Type": "List" + } + }, "Resources": { + "AccessPoint": { + "Properties": { + "FileSystemId": { + "Ref": "EfsFileSystem" + } + }, + "Type": "AWS::EFS::AccessPoint" + }, "EfsFileSystem": { "Type": "AWS::EFS::FileSystem" - }, + }, "LambdaFunctionWithEfs": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "const fs = require('fs')\nconst path = require('path')\nconst efsMountPath = '/mnt/efs'\n\nexports.handler = async (event, context, callback) => {\nconst directory = path.join(efsMountPath, event.body)\nconst files = fs.readdirSync(directory)\nreturn files\n}\n" - }, - "VpcConfig": { - "SubnetIds": { - "Ref": "VpcSubnetIds" - }, - "SecurityGroupIds": { - "Ref": "SecurityGroupIds" - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "LambdaFunctionWithEfsRole", - "Arn" - ] - }, - "Timeout": 3, + }, "FileSystemConfigs": [ { "Arn": { "Fn::GetAtt": [ - "AccessPoint", + "AccessPoint", "Arn" ] - }, + }, "LocalMountPath": "/mnt/EFS" } - ], - "Runtime": "nodejs12.x" - } - }, - "MountTarget": { - "Type": "AWS::EFS::MountTarget", - "Properties": { - "SubnetId": "subnet-abc123", - "FileSystemId": { - "Ref": "EfsFileSystem" - }, - "SecurityGroups": { - "Ref": "SecurityGroupIds" + ], + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionWithEfsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3, + "VpcConfig": { + "SecurityGroupIds": { + "Ref": "SecurityGroupIds" + }, + "SubnetIds": { + "Ref": "VpcSubnetIds" + } } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "LambdaFunctionWithEfsRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "AccessPoint": { - "Type": "AWS::EFS::AccessPoint", + }, + "Type": "AWS::IAM::Role" + }, + "MountTarget": { "Properties": { "FileSystemId": { "Ref": "EfsFileSystem" - } - } - } - }, - "Description": "SAM + Lambda + EFS", - "Parameters": { - "ExistingEfsFileSystem": { - "Type": "String" - }, - "VpcSubnetIds": { - "Type": "List", - "Description": "VPC Subnet IDs that Lambda will use" - }, - "SecurityGroupIds": { - "Type": "List", - "Description": "Security Group IDs that Lambda will use" + }, + "SecurityGroups": { + "Ref": "SecurityGroupIds" + }, + "SubnetId": "subnet-abc123" + }, + "Type": "AWS::EFS::MountTarget" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config.json b/tests/translator/output/aws-us-gov/function_with_function_url_config.json index fc6345ce45..ebbd1822ed 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,59 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -84,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -95,7 +55,47 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json b/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json index 3714b1289d..a79c749e10 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config_and_autopublishalias.json @@ -1,125 +1,125 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, - "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Handler": "index.handler", - "MemorySize": 1024, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Timeout": 3, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, + "Resources": { + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "MyFunctionVersion7eab81fa22": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - } - } + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, - "MyFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MyFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MyFunctionVersion7eab81fa22", - "Version" - ] - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MyFunction" }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunctionAliaslive" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } + "FunctionVersion": { + "Fn::GetAtt": [ + "MyFunctionVersion7eab81fa22", + "Version" + ] }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunctionAliaslive" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunctionAliaslive" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunctionAliaslive" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionVersion7eab81fa22": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MyFunction" } + }, + "Type": "AWS::Lambda::Version" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config_conditions.json b/tests/translator/output/aws-us-gov/function_with_function_url_config_conditions.json index 503d8d4f7c..e2763bcd95 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config_conditions.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config_conditions.json @@ -11,7 +11,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Condition": "MyCondition", "Properties": { "Code": { @@ -28,62 +27,20 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Condition": "MyCondition", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "MyCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -96,7 +53,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -107,7 +65,49 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Condition": "MyCondition", + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config_with_iam_authorization_type.json b/tests/translator/output/aws-us-gov/function_with_function_url_config_with_iam_authorization_type.json index e3252af702..1208b6f22c 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config_with_iam_authorization_type.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config_with_iam_authorization_type.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,48 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "AWS_IAM", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -73,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -84,7 +55,36 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "AWS_IAM", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config_with_intrinsics.json b/tests/translator/output/aws-us-gov/function_with_function_url_config_with_intrinsics.json index beb248c67d..36af376e38 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config_with_intrinsics.json @@ -1,22 +1,21 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { - "AuthorizationTypeRef": { - "Type": "String", - "Default": "NONE" + "AllowMethodsRef": { + "Default": "GET", + "Type": "CommaDelimitedList" }, "AllowOriginsRef": { - "Type": "CommaDelimitedList", - "Default": "https://example.com" + "Default": "https://example.com", + "Type": "CommaDelimitedList" }, - "AllowMethodsRef": { - "Type": "CommaDelimitedList", - "Default": "GET" + "AuthorizationTypeRef": { + "Default": "NONE", + "Type": "String" } }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -32,39 +31,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": { - "Ref": "AuthorizationTypeRef" - }, - "Cors": { - "AllowOrigins": { - "Ref": "AllowOriginsRef" - }, - "AllowMethods": { - "Ref": "AllowMethodsRef" - } - } - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -77,7 +56,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -88,7 +68,27 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": { + "Ref": "AuthorizationTypeRef" + }, + "Cors": { + "AllowMethods": { + "Ref": "AllowMethodsRef" + }, + "AllowOrigins": { + "Ref": "AllowOriginsRef" + } + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_function_url_config_without_cors_config.json b/tests/translator/output/aws-us-gov/function_with_function_url_config_without_cors_config.json index 4464f77ce7..c274150d6e 100644 --- a/tests/translator/output/aws-us-gov/function_with_function_url_config_without_cors_config.json +++ b/tests/translator/output/aws-us-gov/function_with_function_url_config_without_cors_config.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,40 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE" - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,7 +55,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_global_layers.json b/tests/translator/output/aws-us-gov/function_with_global_layers.json index 58bd6af51d..31651635a1 100644 --- a/tests/translator/output/aws-us-gov/function_with_global_layers.json +++ b/tests/translator/output/aws-us-gov/function_with_global_layers.json @@ -1,19 +1,38 @@ { "Resources": { - "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "ManyLayersFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:layer1:1", + "arn:aws:lambda:us-east-1:123456789101:layer:layer2:1", + "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" ], + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ManyLayersFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -26,39 +45,20 @@ ] } } - ] - } - } - }, - "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "python3.6", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:layer1:1", - "arn:aws:lambda:us-east-1:123456789101:layer:layer2:1", - "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" ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_intrinsic_architecture.json b/tests/translator/output/aws-us-gov/function_with_intrinsic_architecture.json index cbb241dc9d..07471d012d 100644 --- a/tests/translator/output/aws-us-gov/function_with_intrinsic_architecture.json +++ b/tests/translator/output/aws-us-gov/function_with_intrinsic_architecture.json @@ -1,14 +1,16 @@ { "Parameters": { "ArchitectureRef": { - "Type": "String", - "Default": "arm64" + "Default": "arm64", + "Type": "String" } }, "Resources": { "FunctionWithArchitecturesIntrinsic": { - "Type": "AWS::Lambda::Function", "Properties": { + "Architectures": { + "Ref": "ArchitectureRef" + }, "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" @@ -23,23 +25,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ], - "Architectures": { - "Ref": "ArchitectureRef" - } - } + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithArchitecturesIntrinsicRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -52,7 +50,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -63,7 +62,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_kmskeyarn.json b/tests/translator/output/aws-us-gov/function_with_kmskeyarn.json index 7ff51981fa..bbdee308a1 100644 --- a/tests/translator/output/aws-us-gov/function_with_kmskeyarn.json +++ b/tests/translator/output/aws-us-gov/function_with_kmskeyarn.json @@ -1,19 +1,32 @@ { "Resources": { - "FunctionWithKeyArnRole": { - "Type": "AWS::IAM::Role", + "FunctionWithKeyArn": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "KmsKeyArn": "thisIsaKey", + "Role": { + "Fn::GetAtt": [ + "FunctionWithKeyArnRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithKeyArnRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -26,24 +39,50 @@ ] } } - ] - } - } - }, - "FunctionWithReferenceToKeyArnRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithReferenceToKeyArn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "KmsKeyArn": { + "Ref": "myKey" + }, + "Role": { + "Fn::GetAtt": [ + "FunctionWithReferenceToKeyArnRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithReferenceToKeyArnRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,82 +95,43 @@ ] } } - ] - } - } - }, - "FunctionWithKeyArn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "KmsKeyArn": "thisIsaKey", - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithKeyArnRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ] + }, + "Type": "AWS::IAM::Role" }, "myKey": { - "Type": "AWS::KMS::Key", "Properties": { + "Description": "A sample key", "KeyPolicy": { - "Version": "2012-10-17", "Id": "key-default-1", "Statement": [ { "Action": [ "kms:Create*" ], - "Sid": "Allow administration of the key", - "Resource": "*", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:user/Alice" - } + }, + "Resource": "*", + "Sid": "Allow administration of the key" } - ] - }, - "Description": "A sample key" - } - }, - "FunctionWithReferenceToKeyArn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "KmsKeyArn": { - "Ref": "myKey" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithReferenceToKeyArnRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ], + "Version": "2012-10-17" + } + }, + "Type": "AWS::KMS::Key" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_layers.json b/tests/translator/output/aws-us-gov/function_with_layers.json index 9197f869c4..835068d2a8 100644 --- a/tests/translator/output/aws-us-gov/function_with_layers.json +++ b/tests/translator/output/aws-us-gov/function_with_layers.json @@ -1,246 +1,246 @@ { "Resources": { - "MinimalLayerFunction": { - "Type": "AWS::Lambda::Function", + "FunctionLayerWithSubIntrinsic": { "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalLayerFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "MyLayera5167acaba": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "MyLayer" - } - }, - "FunctionReferencesLayer": { - "Type": "AWS::Lambda::Function", - "Properties": { + }, + "Handler": "hello.handler", "Layers": [ { - "Ref": "MyLayera5167acaba" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1" + }, { - "Value": "SAM", - "Key": "lambda:createdBy" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1" } - ], - "Handler": "hello.handler", + ], "Role": { "Fn::GetAtt": [ - "FunctionReferencesLayerRole", + "FunctionLayerWithSubIntrinsicRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "MinimalLayerFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionLayerWithSubIntrinsicRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionReferencesLayerRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionNoLayerVersion": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" ], + "Role": { + "Fn::GetAtt": [ + "FunctionNoLayerVersionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionNoLayerVersionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionLayerWithSubIntrinsic": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ - { - "Fn::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" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionLayerWithSubIntrinsicRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "FunctionNoLayerVersion": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionReferencesLayer": { "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ + }, + "Handler": "hello.handler", + "Layers": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "MyLayera5167acaba" } - ], - "Handler": "hello.handler", + ], "Role": { "Fn::GetAtt": [ - "FunctionNoLayerVersionRole", + "FunctionReferencesLayerRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "FunctionNoLayerVersionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionReferencesLayerRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionLayerWithSubIntrinsicRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalLayerFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" ], + "Role": { + "Fn::GetAtt": [ + "MinimalLayerFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalLayerFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_many_layers.json b/tests/translator/output/aws-us-gov/function_with_many_layers.json index 15389c0a61..77973a19b1 100644 --- a/tests/translator/output/aws-us-gov/function_with_many_layers.json +++ b/tests/translator/output/aws-us-gov/function_with_many_layers.json @@ -1,81 +1,81 @@ { "Resources": { - "MyLayera5167acaba": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "MyLayer" - } - }, - "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "ManyLayersFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:z:1", + { + "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" + }, + "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" + }, + { + "Ref": "MyLayera5167acaba" + } ], + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ManyLayersFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:z:1", - { - "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" - }, - "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", - { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" - }, - { - "Ref": "MyLayera5167acaba" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_mq_virtual_host.json b/tests/translator/output/aws-us-gov/function_with_mq_virtual_host.json index 8602b168f3..87ccbab16c 100644 --- a/tests/translator/output/aws-us-gov/function_with_mq_virtual_host.json +++ b/tests/translator/output/aws-us-gov/function_with_mq_virtual_host.json @@ -1,7 +1,6 @@ { "Resources": { "MQFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,34 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Type": "VIRTUAL_HOST", + "URI": "vhost_name" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MQFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,14 +60,14 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", "PolicyDocument": { "Statement": [ { @@ -65,7 +85,8 @@ "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" } ] - } + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" } ], "Tags": [ @@ -74,29 +95,8 @@ "Value": "SAM" } ] - } - }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Type": "VIRTUAL_HOST", - "URI": "vhost_name" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_msk.json b/tests/translator/output/aws-us-gov/function_with_msk.json index 027946a876..c4f59f4cc6 100644 --- a/tests/translator/output/aws-us-gov/function_with_msk.json +++ b/tests/translator/output/aws-us-gov/function_with_msk.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyMskStreamProcessor": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,30 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyMskStreamProcessorMyMskEvent": { + "Properties": { + "AmazonManagedKafkaEventSourceConfig": { + "ConsumerGroupId": "consumergroup1" + }, + "EventSourceArn": { + "Fn::Sub": "arn:aws:kafka:${AWS::Region}:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" + }, + "FunctionName": { + "Ref": "MyMskStreamProcessor" + }, + "StartingPosition": "LATEST", + "Topics": [ + "MyDummyTestTopic" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyMskStreamProcessorRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +58,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -54,25 +71,8 @@ "Value": "SAM" } ] - } - }, - "MyMskStreamProcessorMyMskEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Fn::Sub": "arn:aws:kafka:${AWS::Region}:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" - }, - "FunctionName": { - "Ref": "MyMskStreamProcessor" - }, - "StartingPosition": "LATEST", - "Topics": [ - "MyDummyTestTopic" - ], - "AmazonManagedKafkaEventSourceConfig": { - "ConsumerGroupId": "consumergroup1" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_msk_with_intrinsics.json b/tests/translator/output/aws-us-gov/function_with_msk_with_intrinsics.json index f9e112a81e..d20cdd53ed 100644 --- a/tests/translator/output/aws-us-gov/function_with_msk_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/function_with_msk_with_intrinsics.json @@ -1,26 +1,25 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { + "ConsumerGroupValue": { + "Default": "consumergroup1", + "Type": "String" + }, "StartingPositionValue": { - "Type": "String", - "Default": "LATEST" + "Default": "LATEST", + "Type": "String" }, "StreamValue": { - "Type": "String", - "Default": "arn:aws:kafka:us-east-1:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" + "Default": "arn:aws:kafka:us-east-1:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", + "Type": "String" }, "TopicsValue": { - "Type": "CommaDelimitedList", - "Default": "Topic" - }, - "ConsumerGroupValue": { - "Type": "String", - "Default": "consumergroup1" + "Default": "Topic", + "Type": "CommaDelimitedList" } }, "Resources": { "MyMskStreamProcessor": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -40,13 +39,34 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyMskStreamProcessorMyMskEvent": { + "Properties": { + "AmazonManagedKafkaEventSourceConfig": { + "ConsumerGroupId": { + "Ref": "ConsumerGroupValue" + } + }, + "EventSourceArn": { + "Ref": "StreamValue" + }, + "FunctionName": { + "Ref": "MyMskStreamProcessor" + }, + "StartingPosition": { + "Ref": "StartingPositionValue" + }, + "Topics": { + "Ref": "TopicsValue" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyMskStreamProcessorRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -59,7 +79,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -71,29 +92,8 @@ "Value": "SAM" } ] - } - }, - "MyMskStreamProcessorMyMskEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Ref": "StreamValue" - }, - "FunctionName": { - "Ref": "MyMskStreamProcessor" - }, - "StartingPosition": { - "Ref": "StartingPositionValue" - }, - "Topics": { - "Ref": "TopicsValue" - }, - "AmazonManagedKafkaEventSourceConfig": { - "ConsumerGroupId": { - "Ref": "ConsumerGroupValue" - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_null_events.json b/tests/translator/output/aws-us-gov/function_with_null_events.json index 80f176adf5..18620761f1 100644 --- a/tests/translator/output/aws-us-gov/function_with_null_events.json +++ b/tests/translator/output/aws-us-gov/function_with_null_events.json @@ -1,7 +1,6 @@ { "Resources": { "FunctionWithNullEvents": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithNullEventsRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,7 +50,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_permissions_boundary.json b/tests/translator/output/aws-us-gov/function_with_permissions_boundary.json index f4914ac7c3..3f680ed3c5 100644 --- a/tests/translator/output/aws-us-gov/function_with_permissions_boundary.json +++ b/tests/translator/output/aws-us-gov/function_with_permissions_boundary.json @@ -1,58 +1,58 @@ { "Resources": { - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_policy_templates.json b/tests/translator/output/aws-us-gov/function_with_policy_templates.json index 4ae24a6d45..0b19b790c4 100644 --- a/tests/translator/output/aws-us-gov/function_with_policy_templates.json +++ b/tests/translator/output/aws-us-gov/function_with_policy_templates.json @@ -5,8 +5,7 @@ } }, "Resources": { - "OnePolicyTemplate": { - "Type": "AWS::Lambda::Function", + "AllCombinations": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -15,91 +14,117 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "OnePolicyTemplateRole", + "AllCombinationsRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MultiplePolicyTemplates": { - "Type": "AWS::Lambda::Function", + "AllCombinationsRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MultiplePolicyTemplatesRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "OnePolicyTemplateRole": { - "Type": "AWS::IAM::Role", - "Properties": { "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "OnePolicyTemplateRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "sqs:ChangeMessageVisibility", - "sqs:ChangeMessageVisibilityBatch", - "sqs:DeleteMessage", - "sqs:DeleteMessageBatch", - "sqs:GetQueueAttributes", - "sqs:ReceiveMessage" + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ] + }, + "PolicyName": "AllCombinationsRolePolicy0" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { - "queueName": { - "Fn::Sub": [ - "Some${value}", - { - "value": "KeyId" - } - ] + "functionName": { + "Ref": "FunctionNameParam" } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "AllCombinationsRolePolicy2" } ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MultiplePolicyTemplates": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MultiplePolicyTemplatesRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MultiplePolicyTemplatesRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -112,25 +137,14 @@ ] } } - ] - } - } - }, - "MultiplePolicyTemplatesRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "MultiplePolicyTemplatesRolePolicy0", "PolicyDocument": { "Statement": [ { @@ -142,6 +156,7 @@ "sqs:GetQueueAttributes", "sqs:ReceiveMessage" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -149,20 +164,20 @@ "queueName": "Somekey" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MultiplePolicyTemplatesRolePolicy0" }, { - "PolicyName": "MultiplePolicyTemplatesRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -170,33 +185,23 @@ "functionName": "Some function" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MultiplePolicyTemplatesRolePolicy1" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "AllCombinations": { - "Type": "AWS::Lambda::Function", + "OnePolicyTemplate": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -205,89 +210,84 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "AllCombinationsRole", + "OnePolicyTemplateRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "AllCombinationsRole": { - "Type": "AWS::IAM::Role", + "OnePolicyTemplateRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "AllCombinationsRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } - }, - { - "PolicyName": "AllCombinationsRolePolicy2", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "lambda:InvokeFunction" + "sqs:ChangeMessageVisibility", + "sqs:ChangeMessageVisibilityBatch", + "sqs:DeleteMessage", + "sqs:DeleteMessageBatch", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { - "functionName": { - "Ref": "FunctionNameParam" + "queueName": { + "Fn::Sub": [ + "Some${value}", + { + "value": "KeyId" + } + ] } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "OnePolicyTemplateRolePolicy0" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_request_parameters.json b/tests/translator/output/aws-us-gov/function_with_request_parameters.json index 67345e559c..1281f3b510 100644 --- a/tests/translator/output/aws-us-gov/function_with_request_parameters.json +++ b/tests/translator/output/aws-us-gov/function_with_request_parameters.json @@ -1,13 +1,69 @@ { "Resources": { + "Api": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "parameters": [ + { + "in": "header", + "name": "Authorization", + "required": true, + "type": "string" + } + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "cacheKeyParameters": [ + "method.request.header.Authorization" + ], + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeployment5e67eb8be3": { + "Properties": { + "Description": "RestApi deployment id: 5e67eb8be3d6956bbeadcb3ffdae9abcac90f01e", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiParameterFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ApiParameterFunctionRole", @@ -17,76 +73,35 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "NoApiParameterFunctionRole": { - "Type": "AWS::IAM::Role", + "ApiParameterFunctionGetHtmlPermissionProd": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": "Api", + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiDeploymentbe3a929cf9": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: be3a929cf90555789f2865fc4a96eb9a11ff7a81", - "StageName": "Stage" - } - }, - "ApiDeployment5e67eb8be3": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: 5e67eb8be3d6956bbeadcb3ffdae9abcac90f01e", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, "ApiParameterFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -99,162 +114,147 @@ ] } } - ] - } - } - }, - "NoApiParameterFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "NoApiParameterFunction" + ], + "Version": "2012-10-17" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentbe3a929cf9" + "Ref": "ApiDeployment5e67eb8be3" }, "RestApiId": { - "Ref": "ServerlessRestApi" + "Ref": "Api" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "Api": { - "Type": "AWS::ApiGateway::RestApi", + "NoApiParameterFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" - }, - "cacheKeyParameters": [ - "method.request.header.Authorization" - ] - }, - "responses": {}, - "parameters": [ - { - "required": true, - "type": "string", - "name": "Authorization", - "in": "header" - } - ] - } - } - }, - "swagger": "2.0" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "NoApiParameterFunctionRole", + "Arn" ] }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiParameterFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "NoApiParameterFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "ApiParameterFunction" + "Ref": "NoApiParameterFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "Api" + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "NoApiParameterFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "ApiDeployment5e67eb8be3" - }, - "RestApiId": { - "Ref": "Api" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": false, - "type": "string", + "in": "query", "name": "type", - "in": "query" + "required": false, + "type": "string" }, { - "required": false, - "type": "string", + "in": "path", "name": "id", - "in": "path" + "required": false, + "type": "string" }, { - "required": false, - "type": "string", + "in": "query", "name": "full.type", - "in": "query" + "required": false, + "type": "string" } - ] + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" + } + } } } }, @@ -268,30 +268,30 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "NoApiParameterFunction": { - "Type": "AWS::Lambda::Function", + "ServerlessRestApiDeploymentbe3a929cf9": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" + "Description": "RestApi deployment id: be3a929cf90555789f2865fc4a96eb9a11ff7a81", + "RestApiId": { + "Ref": "ServerlessRestApi" }, - "Role": { - "Fn::GetAtt": [ - "NoApiParameterFunctionRole", - "Arn" - ] + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentbe3a929cf9" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_resource_refs.json b/tests/translator/output/aws-us-gov/function_with_resource_refs.json index b548930542..926aad8a3f 100644 --- a/tests/translator/output/aws-us-gov/function_with_resource_refs.json +++ b/tests/translator/output/aws-us-gov/function_with_resource_refs.json @@ -4,193 +4,193 @@ "Value": { "Ref": "MinimalFunctionAliaslive" } - }, - "VersionArn": { + }, + "AliasInSub": { "Value": { - "Ref": "MinimalFunctionVersion640128d35d" + "Fn::Sub": [ + "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", + { + "SomeValue": "World" + } + ] } - }, - "VersionNumber": { + }, + "AliasName": { "Value": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "MinimalFunctionAliaslive", + "Name" ] } - }, - "AliasName": { + }, + "MustNotResolve": { "Value": { "Fn::GetAtt": [ - "MinimalFunctionAliaslive", - "Name" + "FunctionWithoutAlias", + "Alias.Name" ] } - }, + }, "UnResolvedVersion": { "Value": { "Ref": "FunctionWithoutAlias.Version" } - }, - "AliasInSub": { + }, + "VersionArn": { "Value": { - "Fn::Sub": [ - "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", - { - "SomeValue": "World" - } - ] + "Ref": "MinimalFunctionVersion640128d35d" } - }, - "MustNotResolve": { + }, + "VersionNumber": { "Value": { "Fn::GetAtt": [ - "FunctionWithoutAlias", - "Alias.Name" + "MinimalFunctionVersion640128d35d", + "Version" ] } } - }, + }, "Resources": { "FunctionWithoutAlias": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithoutAliasRole", + "FunctionWithoutAliasRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithoutAliasRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithoutAliasRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "MyBucket": { - "Type": "AWS::S3::Bucket", "Properties": { "Name": { "Fn::GetAtt": [ - "MinimalFunctionAliaslive", + "MinimalFunctionAliaslive", "Name" ] } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + }, + "Type": "AWS::S3::Bucket" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_self_managed_kafka.json b/tests/translator/output/aws-us-gov/function_with_self_managed_kafka.json index 78693ba8f2..f39db6c533 100644 --- a/tests/translator/output/aws-us-gov/function_with_self_managed_kafka.json +++ b/tests/translator/output/aws-us-gov/function_with_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,48 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SelfManagedKafkaEventSourceConfig": { + "ConsumerGroupId": "consumergroup1" + }, + "SourceAccessConfigurations": [ + { + "Type": "SASL_SCRAM_512_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +76,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -82,43 +117,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "SASL_SCRAM_512_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - }, - "SelfManagedKafkaEventSourceConfig": { - "ConsumerGroupId": "consumergroup1" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_signing_profile.json b/tests/translator/output/aws-us-gov/function_with_signing_profile.json index fb4065fa59..769f181178 100644 --- a/tests/translator/output/aws-us-gov/function_with_signing_profile.json +++ b/tests/translator/output/aws-us-gov/function_with_signing_profile.json @@ -1,36 +1,34 @@ { "Resources": { "FunctionWithSigningProfile": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + "CodeSigningConfigArn": { + "Ref": "MySignedFunctionCodeSigningConfig" + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionWithSigningProfileRole", "Arn" ] }, - "CodeSigningConfigArn": { - "Ref": "MySignedFunctionCodeSigningConfig" - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithSigningProfileRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -43,25 +41,23 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySignedFunctionCodeSigningConfig": { - "Type": "AWS::Lambda::CodeSigningConfig", "Properties": { - "CodeSigningPolicies": { - "UntrustedArtifactOnDeployment": "Enforce" - }, "AllowedPublishers": { "SigningProfileVersionArns": [ { @@ -72,14 +68,18 @@ } ] }, + "CodeSigningPolicies": { + "UntrustedArtifactOnDeployment": "Enforce" + }, "Description": "Code Signing for MySignedLambdaFunction" - } + }, + "Type": "AWS::Lambda::CodeSigningConfig" }, "SigningProfile": { - "Type": "AWS::Signer::SigningProfile", "Properties": { "PlatformId": "AWSLambda-SHA384-ECDSA" - } + }, + "Type": "AWS::Signer::SigningProfile" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/function_with_sns_event_source_all_parameters.json b/tests/translator/output/aws-us-gov/function_with_sns_event_source_all_parameters.json index 87237d78bb..6368519482 100644 --- a/tests/translator/output/aws-us-gov/function_with_sns_event_source_all_parameters.json +++ b/tests/translator/output/aws-us-gov/function_with_sns_event_source_all_parameters.json @@ -1,22 +1,47 @@ { "Resources": { + "MyAwesomeFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyAwesomeFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "MyAwesomeFunction", + "Arn" + ] + }, "FilterPolicy": { - "store": [ - "example_corp" + "customer_interests": [ + "rugby", + "football", + "baseball" ], "event": [ { "anything-but": "order_cancelled" } ], - "customer_interests": [ - "rugby", - "football", - "baseball" - ], "price_usd": [ { "numeric": [ @@ -24,44 +49,31 @@ 100 ] } - ] - }, - "Endpoint": { - "Fn::GetAtt": [ - "MyAwesomeFunction", - "Arn" + ], + "store": [ + "example_corp" ] }, "Protocol": "lambda", - "TopicArn": "topicArn", - "Region": "region" - } + "Region": "region", + "TopicArn": "topicArn" + }, + "Type": "AWS::SNS::Subscription" }, "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunction" }, + "Principal": "sns.amazonaws.com", "SourceArn": "topicArn" - } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -74,32 +86,20 @@ ] } } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MyAwesomeFunctionRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/function_with_vpc_permission_for_self_managed_kafka.json b/tests/translator/output/aws-us-gov/function_with_vpc_permission_for_self_managed_kafka.json index 3316f1648c..d6bdf6adb1 100644 --- a/tests/translator/output/aws-us-gov/function_with_vpc_permission_for_self_managed_kafka.json +++ b/tests/translator/output/aws-us-gov/function_with_vpc_permission_for_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,41 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SourceAccessConfigurations": [ + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +69,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -75,36 +103,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json b/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json index cdcf96bc20..633d47f15d 100644 --- a/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json +++ b/tests/translator/output/aws-us-gov/global_handle_path_level_parameter.json @@ -1,102 +1,47 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "parameters": [ - { - "required": true, - "type": "string", - "description": "Application domain", - "name": "domain", - "in": "path" - } - ], "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "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" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } + } + }, + "parameters": [ + { + "description": "Application domain", + "in": "path", + "name": "domain", + "required": true, + "type": "string" + } + ] } }, - "swagger": 2.0, "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -110,7 +55,8 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": 2.0 }, "EndpointConfiguration": { "Types": [ @@ -121,80 +67,112 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ExplicitApiDeployment9a254aa466": { "Properties": { + "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" + "Ref": "ExplicitApi" }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentc969c99f9d" - } - } + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment9a254aa466" + }, "RestApiId": { "Ref": "ExplicitApi" }, "StageName": "SomeStage", - "CacheClusterSize": "1.6", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment9a254aa466" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "ServerlessRestApiDeploymentc969c99f9d": { - "Type": "AWS::ApiGateway::Deployment", + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", - "StageName": "Stage" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 @@ -203,57 +181,50 @@ "Schema": [ { "AttributeDataType": "String", - "Required": false, - "Name": "email" + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, - "ExplicitApiDeployment9a254aa466": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", - "StageName": "Stage" - } + }, + "Type": "AWS::Cognito::UserPool" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -267,7 +238,8 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ @@ -278,7 +250,35 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentc969c99f9d": { + "Properties": { + "Description": "RestApi deployment id: c969c99f9d6b6921dff605a206e8989bdb7d1bc7", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentc969c99f9d" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/globals_for_api.json b/tests/translator/output/aws-us-gov/globals_for_api.json index feedaa8236..0f1844e2ca 100644 --- a/tests/translator/output/aws-us-gov/globals_for_api.json +++ b/tests/translator/output/aws-us-gov/globals_for_api.json @@ -1,291 +1,291 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "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": {}, "security": [ { "MyCognitoAuth": [] - }, + }, { "api_key": [] } - ], - "responses": {} + ], + "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" + } + } } } - }, - "swagger": 2.0, + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": 2.0 + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment43e01e673d": { "Properties": { + "Description": "RestApi deployment id: 43e01e673d7acbd09e4c38ff78dd6ddaf2ed1d55", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment6fd1928d9b" - } - } - }, + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment43e01e673d" + }, "RestApiId": { "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", + }, + "StageName": "SomeStage", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment43e01e673d" } - } - }, - "ExplicitApiDeployment43e01e673d": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 43e01e673d7acbd09e4c38ff78dd6ddaf2ed1d55", - "StageName": "Stage" - } - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiDeployment6fd1928d9b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 6fd1928d9b9ad3c711a371e1337306458029f8bd", - "StageName": "Stage" - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 } - }, + }, "Schema": [ { - "AttributeDataType": "String", - "Required": false, - "Name": "email" + "AttributeDataType": "String", + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, + }, + "Type": "AWS::Cognito::UserPool" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" - } - }, + "responses": {}, "security": [ { "MyCognitoAuth": [] - }, + }, { "api_key": [] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ImplicitApiFunction.Arn}/invocations" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, - "Name": "some api", + }, + "Name": "some api", "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment6fd1928d9b": { + "Properties": { + "Description": "RestApi deployment id: 6fd1928d9b9ad3c711a371e1337306458029f8bd", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment6fd1928d9b" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/globals_for_function.json b/tests/translator/output/aws-us-gov/globals_for_function.json index cfd77a3e90..851c367409 100644 --- a/tests/translator/output/aws-us-gov/globals_for_function.json +++ b/tests/translator/output/aws-us-gov/globals_for_function.json @@ -1,251 +1,255 @@ { "Resources": { - "FunctionWithOverridesRole": { - "Type": "AWS::IAM::Role", + "FunctionWithOverrides": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Architectures": [ + "x86_64" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Environment": { + "Variables": { + "Var1": "value1", + "Var2": "value2", + "Var3": "value3" + } + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "index.handler", + "Layers": [ { - "Value": "newvalue1", - "Key": "newtag1" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" }, { - "Value": "value1", - "Key": "tag1" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "MemorySize": 512, + "ReservedConcurrentExecutions": 100, + "Role": { + "Fn::GetAtt": [ + "FunctionWithOverridesRole", + "Arn" ] - } - } - }, - "FunctionWithOverrides": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" + "Key": "newtag1", + "Value": "newvalue1" + }, + { + "Key": "tag1", + "Value": "value1" } - ], + ], + "Timeout": 100, "TracingConfig": { "Mode": "PassThrough" - }, - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + }, "VpcConfig": { - "SubnetIds": [ - "sub-id-2" - ], "SecurityGroupIds": [ - "sg-edcd9784", + "sg-edcd9784", "sg-123" + ], + "SubnetIds": [ + "sub-id-2" ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "newvalue1", - "Key": "newtag1" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "ReservedConcurrentExecutions": 100, - "Architectures": ["x86_64"], - "EphemeralStorage": { - "Size": 1024 + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithOverridesAliasprod": { + "Properties": { + "FunctionName": { + "Ref": "FunctionWithOverrides" }, - "MemorySize": 512, - "Environment": { - "Variables": { - "Var1": "value1", - "Var3": "value3", - "Var2": "value2" - } - }, - "Handler": "index.handler", - "Role": { + "FunctionVersion": { "Fn::GetAtt": [ - "FunctionWithOverridesRole", - "Arn" + "FunctionWithOverridesVersion096ed3b52b", + "Version" ] - }, - "Timeout": 100, - "Runtime": "nodejs12.x" - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Name": "prod" + }, + "Type": "AWS::Lambda::Alias" + }, + "FunctionWithOverridesRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithOverridesAliasprod": { - "Type": "AWS::Lambda::Alias", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "newtag1", + "Value": "newvalue1" + }, + { + "Key": "tag1", + "Value": "value1" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithOverridesVersion096ed3b52b": { + "DeletionPolicy": "Retain", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionWithOverridesVersion096ed3b52b", - "Version" - ] - }, "FunctionName": { "Ref": "FunctionWithOverrides" - }, - "Name": "prod" - } - }, + } + }, + "Type": "AWS::Lambda::Version" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Layers": [ - { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" - } - ], - "TracingConfig": { - "Mode": "Active" - }, + "Architectures": [ + "x86_64" + ], "Code": { - "S3Bucket": "global-bucket", + "S3Bucket": "global-bucket", "S3Key": "global.zip" - }, - "VpcConfig": { - "SubnetIds": [ - "sub-id-2" - ], - "SecurityGroupIds": [ - "sg-edcd9784" - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "ReservedConcurrentExecutions": 50, - "Architectures": ["x86_64"], - "EphemeralStorage": { - "Size": 1024 }, - "MemorySize": 1024, "Environment": { "Variables": { - "Var1": "value1", + "Var1": "value1", "Var2": "value2" } - }, - "Handler": "hello.handler", + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "hello.handler", + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + } + ], + "MemorySize": 1024, + "ReservedConcurrentExecutions": 50, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Timeout": 30, - "Runtime": "python2.7" - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "tag1", + "Value": "value1" + } + ], + "Timeout": 30, + "TracingConfig": { + "Mode": "Active" + }, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "sub-id-2" + ] + } + }, + "Type": "AWS::Lambda::Function" + }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ "MinimalFunctionVersion0a06fc8fb1", "Version" ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, + }, "Name": "live" - } - }, - "FunctionWithOverridesVersion096ed3b52b": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { "Properties": { - "FunctionName": { - "Ref": "FunctionWithOverrides" - } - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "tag1", + "Value": "value1" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion0a06fc8fb1": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/globals_for_simpletable.json b/tests/translator/output/aws-us-gov/globals_for_simpletable.json index 313fd286c3..d937d9ef86 100644 --- a/tests/translator/output/aws-us-gov/globals_for_simpletable.json +++ b/tests/translator/output/aws-us-gov/globals_for_simpletable.json @@ -1,25 +1,25 @@ { - "Resources": { - "MinimalTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "SSESpecification": { - "SSEEnabled": true - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] + "Resources": { + "MinimalTable": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "SSESpecification": { + "SSEEnabled": true } - } + }, + "Type": "AWS::DynamoDB::Table" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/http_api_custom_iam_auth.json b/tests/translator/output/aws-us-gov/http_api_custom_iam_auth.json index 3266785221..5d6731ede4 100644 --- a/tests/translator/output/aws-us-gov/http_api_custom_iam_auth.json +++ b/tests/translator/output/aws-us-gov/http_api_custom_iam_auth.json @@ -2,22 +2,42 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionHelloAWSIAMAuthPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "MyApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/hello-aws-iam-auth" ] } @@ -29,9 +49,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -39,7 +65,12 @@ "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -53,7 +84,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -61,13 +95,22 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/hello-aws-iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -80,8 +123,14 @@ } }, "tags": [ - { "name": "Tag1", "x-amazon-apigateway-tag-value": "value1" }, - { "name": "Tag2", "x-amazon-apigateway-tag-value": "value2" }, + { + "name": "Tag1", + "x-amazon-apigateway-tag-value": "value1" + }, + { + "name": "Tag2", + "x-amazon-apigateway-tag-value": "value2" + }, { "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" @@ -93,7 +142,9 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", "Tags": { @@ -106,11 +157,24 @@ }, "MyAuthFn": { "Properties": { - "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, "Handler": "index.handler", - "Role": { "Fn::GetAtt": ["Arn", "MyAuthFnRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "MyAuthFnRole" + ] + }, "Runtime": "nodejs12.x", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, @@ -119,9 +183,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -129,7 +199,12 @@ "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" } diff --git a/tests/translator/output/aws-us-gov/http_api_def_uri.json b/tests/translator/output/aws-us-gov/http_api_def_uri.json index 5190687504..fed6146d18 100644 --- a/tests/translator/output/aws-us-gov/http_api_def_uri.json +++ b/tests/translator/output/aws-us-gov/http_api_def_uri.json @@ -1,151 +1,151 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionApi2Permission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", - "__ApiId__": "MyApi" + "__ApiId__": { + "Ref": "MyApi2" + }, + "__Stage__": "*" } ] } - } - }, - "MyApiStage": { - "Type": "AWS::ApiGatewayV2::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionApiPermission": { "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "DefaultRouteSettings": { - "ThrottlingBurstLimit": 50, - "ThrottlingRateLimit": 100.0 - }, - "StageName": { - "Fn::Join": [ - "", - [ - "Stage", - "Name" - ] + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": "MyApi", + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "MyApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "bucket", + "Key": "key" + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2": { + "Properties": { + "BodyS3Location": { + "Bucket": "bucket", + "Key": "key", + "Version": "version" + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi2" - }, + }, "AutoDeploy": true, "DefaultRouteSettings": { - "ThrottlingRateLimit": 100 + "ThrottlingRateLimit": 100 }, "StageName": "$default" - } - }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "BodyS3Location": { - "Version": "version", - "Bucket": "bucket", - "Key": "key" - } - } - }, - "FunctionApi2Permission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApiStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi2" - } - } + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingBurstLimit": 50, + "ThrottlingRateLimit": 100.0 + }, + "StageName": { + "Fn::Join": [ + "", + [ + "Stage", + "Name" + ] ] } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "BodyS3Location": { - "Bucket": "bucket", - "Key": "key" - } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/http_api_description.json b/tests/translator/output/aws-us-gov/http_api_description.json index dd4a7f36c9..d1a53fb48e 100644 --- a/tests/translator/output/aws-us-gov/http_api_description.json +++ b/tests/translator/output/aws-us-gov/http_api_description.json @@ -1,123 +1,123 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", - "__ApiId__": "HttpApi" + "__ApiId__": "HttpApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "HttpApi" - }, - "Tags": { - "httpapi:createdBy": "SAM" - }, - "StageName": "$default" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "HttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "info": { + "description": "my description" + }, "openapi": "3.0.1", "paths": { - "/foo": {}, "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {} + } } - } + }, + "/foo": {} }, "tags": [ { "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ], - "info": { - "description": "my description" - } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "HttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "HttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/http_api_existing_openapi.json b/tests/translator/output/aws-us-gov/http_api_existing_openapi.json index 5efdccc329..06cd80b982 100644 --- a/tests/translator/output/aws-us-gov/http_api_existing_openapi.json +++ b/tests/translator/output/aws-us-gov/http_api_existing_openapi.json @@ -1,276 +1,276 @@ { "Parameters": { "Timeout": { - "Default": 15000, + "Default": 15000, "Type": "Number" } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "OpenIdAuth": { + "type": "openIdConnect", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "openIdConnectUrl": "https://www.example.com/v1/connect", + "type": "jwt" + } + }, + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get/{something}/with/{params}": { - "get": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope1", + "scope2" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "timeoutInMillis": { + "Ref": "Timeout" + }, + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {}, - "parameters": [ - { - "required": true, - "name": "something", - "in": "path" - }, - { - "required": true, - "name": "params", - "in": "path" } - ] + } } - }, + }, "/basic": { "post": { - "x-amazon-apigateway-integration": { - "payloadFormatVersion": "1.0", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "httpMethod": "POST", - "timeoutInMillis": 10000 - }, + "responses": {}, "security": [ { "OpenIdAuth": [ "scope3" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "timeoutInMillis": 10000, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } } - }, - "/integration": { - "post": { + }, + "/get/{something}/with/{params}": { + "get": { + "parameters": [ + { + "in": "path", + "name": "something", + "required": true + }, + { + "in": "path", + "name": "params", + "required": true + } + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope1", - "scope2" - ] } - ], - "responses": {} + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/integration": { + "post": { + "responses": {}, "security": [ { "OpenIdAuth": [ - "scope1", + "scope1", "scope2" ] } - ], - "isDefaultRoute": true, + ], "x-amazon-apigateway-integration": { - "payloadFormatVersion": "1.0", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "httpMethod": "POST", - "timeoutInMillis": { - "Ref": "Timeout" } - }, - "responses": {} + } } - }, + }, "/oauth2": { "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } } - }, + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ], "x-amazon-apigateway-cors": { - "allowMethods": [ - "GET" - ], "allowHeaders": [ "x-apigateway-header" - ], + ], + "allowMethods": [ + "GET" + ], "allowOrigins": [ - "https://global.com", + "https://global.com", "https://local.com" - ], + ], "maxAge": 6000 - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - }, - "OpenIdAuth": { - "type": "openIdConnect", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "openIdConnectUrl": "https://www.example.com/v1/connect" - } - } - } } } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/http_api_existing_openapi_conditions.json b/tests/translator/output/aws-us-gov/http_api_existing_openapi_conditions.json index 22e36ce32e..e0c75acd1e 100644 --- a/tests/translator/output/aws-us-gov/http_api_existing_openapi_conditions.json +++ b/tests/translator/output/aws-us-gov/http_api_existing_openapi_conditions.json @@ -2,295 +2,295 @@ "Conditions": { "condition": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "condition" - }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM", - "Tag1": "value1", - "Tag2": "value2" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "condition", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "condition" - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "condition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "condition" - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Condition": "condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "OAuth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + }, + "OpenIdAuth": { + "type": "openIdConnect", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "openIdConnectUrl": "https://www.example.com/v1/connect", + "type": "jwt" + } + }, + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope3" - ] - } - ], - "responses": {} - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OAuth2": [ - "basic" - ] - } - ], - "responses": {} - } - }, - "/integration": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope1", - "scope2" - ] - } - ], - "responses": {} - } - }, "$default": { "x-amazon-apigateway-any-method": { "Fn::If": [ - "condition", + "condition", { + "isDefaultRoute": true, + "responses": {}, "security": [ { "OpenIdAuth": [ - "scope1", + "scope1", "scope2" ] } - ], - "isDefaultRoute": true, + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "condition", + "condition", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, - "/oauth2": { + }, + "/basic": { + "get": { + "responses": {}, + "security": [ + { + "OAuth2": [ + "basic" + ] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } + }, "post": { + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope3" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } + } + }, + "/integration": { + "post": { + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope1", + "scope2" + ] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, + } + } + } + }, + "/oauth2": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - } - }, - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - }, - "OAuth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } } - }, - "OpenIdAuth": { - "type": "openIdConnect", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "openIdConnectUrl": "https://www.example.com/v1/connect" - } } } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" }, { - "name": "Tag1", - "x-amazon-apigateway-tag-value": "value1", - "description": "this tag exists, but doesn't have an amazon extension value" - }, + "description": "this tag exists, but doesn't have an amazon extension value", + "name": "Tag1", + "x-amazon-apigateway-tag-value": "value1" + }, { - "name": "Tag2", + "name": "Tag2", "x-amazon-apigateway-tag-value": "value2" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "Tag1": "value1", + "Tag2": "value2", + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/http_api_explicit_stage.json b/tests/translator/output/aws-us-gov/http_api_explicit_stage.json index 6fbeb6689d..1b07f1df84 100644 --- a/tests/translator/output/aws-us-gov/http_api_explicit_stage.json +++ b/tests/translator/output/aws-us-gov/http_api_explicit_stage.json @@ -1,160 +1,160 @@ { "Parameters": { "CorsParam": { - "Default": true, + "Default": true, "Type": "String" }, "PayloadFormatVersion": { - "Default": "1.0", - "Type": "String" + "Default": "1.0", + "Type": "String" } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "StageVariables": { - "VarName": "VarValue" - }, - "AccessLogSettings": { - "DestinationArn": "arn:aws:logs:us-east-1:123456789012:log-group:LogGroupName", - "Format": "$context.requestId" - }, - "StageName": "Prod", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "RouteSettings": { - "$default": { - "ThrottlingRateLimit": 0.7, - "DataTraceEnabled": true, - "ThrottlingBurstLimit": 300, - "LoggingLevel": "INFO" - } - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { - "FailOnWarnings": true, "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, + "httpMethod": "POST", "payloadFormatVersion": { "Ref": "PayloadFormatVersion" + }, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {} + } } } - }, - "x-amazon-apigateway-cors": { - "allowOrigins": [ - "*" - ] - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ] + ], + "x-amazon-apigateway-cors": { + "allowOrigins": [ + "*" + ] + } + }, + "FailOnWarnings": true + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "AccessLogSettings": { + "DestinationArn": "arn:aws:logs:us-east-1:123456789012:log-group:LogGroupName", + "Format": "$context.requestId" + }, + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "RouteSettings": { + "$default": { + "DataTraceEnabled": true, + "LoggingLevel": "INFO", + "ThrottlingBurstLimit": 300, + "ThrottlingRateLimit": 0.7 + } + }, + "StageName": "Prod", + "StageVariables": { + "VarName": "VarValue" + }, + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled.json b/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled.json index de3f06ee56..be95b92dfa 100644 --- a/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled.json +++ b/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled.json @@ -2,22 +2,42 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionImplicitApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "ServerlessHttpApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" ] } @@ -27,11 +47,18 @@ "HttpApiFunctionImplicitApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "ServerlessHttpApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" ] } @@ -43,9 +70,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -53,7 +86,12 @@ "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -70,7 +108,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { @@ -89,7 +132,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -113,10 +160,14 @@ }, "ServerlessHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "ServerlessHttpApi" }, + "ApiId": { + "Ref": "ServerlessHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json b/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json index ceea480e89..e9e8279554 100644 --- a/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json +++ b/tests/translator/output/aws-us-gov/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json @@ -10,7 +10,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -18,7 +21,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": {}, "tags": [ @@ -33,10 +41,14 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-us-gov/http_api_lambda_auth.json b/tests/translator/output/aws-us-gov/http_api_lambda_auth.json index bf4184c641..efa0290cc5 100644 --- a/tests/translator/output/aws-us-gov/http_api_lambda_auth.json +++ b/tests/translator/output/aws-us-gov/http_api_lambda_auth.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,149 +71,96 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerPayloadFormatVersion": 1.0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "request" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/basic": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerPayloadFormatVersion": 1.0 } } } @@ -234,22 +180,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "AutoDeploy": true - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/http_api_lambda_auth_full.json b/tests/translator/output/aws-us-gov/http_api_lambda_auth_full.json index 3fe74a2187..8c443ce922 100644 --- a/tests/translator/output/aws-us-gov/http_api_lambda_auth_full.json +++ b/tests/translator/output/aws-us-gov/http_api_lambda_auth_full.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,163 +71,110 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 2.0, + "authorizerResultTtlInSeconds": 60, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "enableSimpleResponses": true, + "identitySource": [ + "$context.contextVar", + "$request.header.Authorization", + "$request.querystring.petId", + "$stageVariables.stageVar" + ], + "type": "request" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/basic": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "identitySource": [ - "$context.contextVar", - "$request.header.Authorization", - "$request.querystring.petId", - "$stageVariables.stageVar" - ], - "authorizerResultTtlInSeconds": 60, - "authorizerPayloadFormatVersion": 2.0, - "enableSimpleResponses": true } } } @@ -248,22 +194,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "AutoDeploy": true - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled.json b/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled.json index c488588336..a3061470a2 100644 --- a/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled.json +++ b/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled.json @@ -2,23 +2,40 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionMyDefaultIamAuthHttpApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" @@ -30,12 +47,16 @@ "HttpApiFunctionMyDefaultIamAuthHttpApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" @@ -47,12 +68,16 @@ "HttpApiFunctionMyDefaultIamAuthHttpApiNoAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-auth" @@ -64,12 +89,16 @@ "HttpApiFunctionMyIamAuthEnabledHttpApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyIamAuthEnabledHttpApi" }, + "__ApiId__": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" @@ -81,12 +110,16 @@ "HttpApiFunctionMyIamAuthEnabledHttpApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyIamAuthEnabledHttpApi" }, + "__ApiId__": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" @@ -100,9 +133,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -110,7 +149,12 @@ "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -127,13 +171,22 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -147,7 +200,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -161,7 +218,11 @@ "/no-auth": { "get": { "responses": {}, - "security": [{ "NONE": [] }], + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -185,10 +246,14 @@ }, "MyDefaultIamAuthHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyDefaultIamAuthHttpApi" }, + "ApiId": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" }, @@ -205,7 +270,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { @@ -224,7 +294,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -248,10 +322,14 @@ }, "MyIamAuthEnabledHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyIamAuthEnabledHttpApi" }, + "ApiId": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json b/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json index ceea480e89..e9e8279554 100644 --- a/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json +++ b/tests/translator/output/aws-us-gov/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json @@ -10,7 +10,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -18,7 +21,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": {}, "tags": [ @@ -33,10 +41,14 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/aws-us-gov/http_api_multiple_authorizers.json b/tests/translator/output/aws-us-gov/http_api_multiple_authorizers.json index 3f705ca939..251a132336 100644 --- a/tests/translator/output/aws-us-gov/http_api_multiple_authorizers.json +++ b/tests/translator/output/aws-us-gov/http_api_multiple_authorizers.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -9,7 +8,10 @@ }, "Handler": "index.restapi", "Role": { - "Fn::GetAtt": ["HttpApiFunctionRole", "Arn"] + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] }, "Runtime": "python3.7", "Tags": [ @@ -18,22 +20,26 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -44,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -65,190 +71,152 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": ["MyAuthFnRole", "Arn"] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": ["sts:AssumeRole"], - "Effect": "Allow", - "Principal": { - "Service": ["lambda.amazonaws.com"] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + }, + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerPayloadFormatVersion": 1.0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "request" + } + }, + "MyOauth2Authorizer": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.header.Authorization", + "jwtConfiguration": { + "audience": [ + "audience1", + "audience2" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/hello": { - "get": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/hello": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyOauth2Authorizer": ["scope"] + "LambdaAuth": [] } - ] - }, - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { - "LambdaAuth": [] + "MyOauth2Authorizer": [ + "scope" + ] } - ] - } - }, - "/hello-aws-iam-auth": { - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/hello-aws-iam-auth": { + "get": { "responses": {}, "security": [ { "AWS_IAM": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "AWS_IAM": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "awsSigv4" - }, - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": ["MyAuthFn", "Arn"] - } - } - ] - }, - "authorizerPayloadFormatVersion": 1.0 - } - }, - "MyOauth2Authorizer": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "jwtConfiguration": { - "audience": ["audience1", "audience2"], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "identitySource": "$request.header.Authorization", - "type": "jwt" } } } @@ -268,22 +236,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "AutoDeploy": true - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/http_api_with_cors.json b/tests/translator/output/aws-us-gov/http_api_with_cors.json index 7b9ed1d105..84bf17d042 100644 --- a/tests/translator/output/aws-us-gov/http_api_with_cors.json +++ b/tests/translator/output/aws-us-gov/http_api_with_cors.json @@ -2,243 +2,243 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} - } - } - }, - "x-amazon-apigateway-cors": { - "Fn::If": [ - "C1", - { - "allowHeaders": [ - "x-apigateway-header" - ], - "allowMethods": [ - "GET" - ], - "allowOrigins": [ - "https://foo.com" - ], - "exposeHeaders": [ - "x-amzn-header" - ] - }, - "AWS::NoValue" - ] - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n console.log(\"Hello from MyAuthFunction\")\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionImplicitApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ], "x-amazon-apigateway-cors": { "Fn::If": [ - "C1", + "C1", { "allowHeaders": [ "x-apigateway-header" - ], + ], "allowMethods": [ "GET" - ], + ], "allowOrigins": [ "https://foo.com" - ], + ], "exposeHeaders": [ "x-amzn-header" ] - }, + }, "AWS::NoValue" ] - }, - "openapi": "3.0.1", + } + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "ServerlessHttpApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } + } + } + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ] + ], + "x-amazon-apigateway-cors": { + "Fn::If": [ + "C1", + { + "allowHeaders": [ + "x-apigateway-header" + ], + "allowMethods": [ + "GET" + ], + "allowOrigins": [ + "https://foo.com" + ], + "exposeHeaders": [ + "x-amzn-header" + ] + }, + "AWS::NoValue" + ] + } + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/http_api_with_custom_domain_route53_multiple.json b/tests/translator/output/aws-us-gov/http_api_with_custom_domain_route53_multiple.json index 1be40930c5..4027452a35 100644 --- a/tests/translator/output/aws-us-gov/http_api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/aws-us-gov/http_api_with_custom_domain_route53_multiple.json @@ -1,255 +1,255 @@ { - "Resources": { - "MyApi1": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, - "ApiGatewayDomainNameV25fe29fe649": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.one.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApi1ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi1" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV25fe29fe649" - }, - "Stage": { - "Ref": "MyApi1ApiGatewayDefaultStage" - } - } - }, - "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "abc123456", - "RecordSets": [ - { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV23fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV23fd2dbd8f8", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.three.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV241bfc7f9c4", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV241bfc7f9c4", - "RegionalDomainName" - ] - } - } - } - ] + "Resources": { + "ApiGatewayDomainNameV23fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "ApiGatewayDomainNameV241bfc7f9c4": { + "Properties": { + "DomainName": "admin.three.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "ApiGatewayDomainNameV25fe29fe649": { + "Properties": { + "DomainName": "admin.one.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi1": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi1ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi1" }, - "MyApi1ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi1" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi1ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi1" }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV25fe29fe649" }, - "ApiGatewayDomainNameV23fd2dbd8f8": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.two.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } + "Stage": { + "Ref": "MyApi1ApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApi2": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" }, - "MyApi2ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV23fd2dbd8f8" - }, - "Stage": { - "Ref": "MyApi2ApiGatewayDefaultStage" - } - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi2ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" }, - "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV23fd2dbd8f8" }, - "MyApi3": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } + "Stage": { + "Ref": "MyApi2ApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApi3": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi3ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi3" }, - "ApiGatewayDomainNameV241bfc7f9c4": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.three.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi3ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi3" }, - "MyApi3ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi3" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV241bfc7f9c4" - }, - "Stage": { - "Ref": "MyApi3ApiGatewayDefaultStage" - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV241bfc7f9c4" }, - "MyApi3ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi3" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "Stage": { + "Ref": "MyApi3ApiGatewayDefaultStage" } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "RecordSetGroup370194ff6e": { + "Properties": { + "HostedZoneId": "abc123456", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV23fd2dbd8f8", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV23fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV241bfc7f9c4", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV241bfc7f9c4", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.three.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/http_api_with_null_path.json b/tests/translator/output/aws-us-gov/http_api_with_null_path.json index db435477ac..2992a5599b 100644 --- a/tests/translator/output/aws-us-gov/http_api_with_null_path.json +++ b/tests/translator/output/aws-us-gov/http_api_with_null_path.json @@ -1,122 +1,122 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", - "Resources": { - "EXAMPLEPARTIALLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "EXAMPLEPARTIALLambdaRole", - "Arn" - ] - }, - "Runtime": "python3.9", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "EXAMPLEPARTIALLambdaRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", + "Resources": { + "EXAMPLEPARTIALGateway": { + "Properties": { + "Body": { + "openapi": "3.0.1", + "paths": { + "/my/route": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EXAMPLEPARTIALLambda.Arn}/invocations" + } } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "EXAMPLEPARTIALLambdaPostRequestPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "EXAMPLEPARTIALLambda" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/my/route", - { - "__ApiId__": { - "Ref": "EXAMPLEPARTIALGateway" - }, - "__Stage__": "*" - } - ] + "Type": "AWS::ApiGatewayV2::Api" + }, + "EXAMPLEPARTIALGatewayApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "EXAMPLEPARTIALGateway" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "EXAMPLEPARTIALLambda": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "EXAMPLEPARTIALLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.9", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "EXAMPLEPARTIALLambdaPostRequestPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "EXAMPLEPARTIALLambda" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/my/route", + { + "__ApiId__": { + "Ref": "EXAMPLEPARTIALGateway" + }, + "__Stage__": "*" + } + ] } }, - "EXAMPLEPARTIALGateway": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "openapi": "3.0.1", - "paths": { - "/my/route": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EXAMPLEPARTIALLambda.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Type": "AWS::Lambda::Permission" + }, + "EXAMPLEPARTIALLambdaRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "EXAMPLEPARTIALGatewayApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "EXAMPLEPARTIALGateway" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } - } + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/implicit_and_explicit_api_with_conditions.json b/tests/translator/output/aws-us-gov/implicit_and_explicit_api_with_conditions.json index 2c5bb78900..cc7a2a70f9 100644 --- a/tests/translator/output/aws-us-gov/implicit_and_explicit_api_with_conditions.json +++ b/tests/translator/output/aws-us-gov/implicit_and_explicit_api_with_conditions.json @@ -11,341 +11,68 @@ } ] }, - "explicithello2condition": { + "explicithello1condition": { "Fn::Equals": [ true, false ] }, - "implicithello1condition": { + "explicithello2condition": { "Fn::Equals": [ true, false ] }, - "implicithello2condition": { + "implicithello1condition": { "Fn::Equals": [ true, false ] }, - "explicithello1condition": { + "implicithello2condition": { "Fn::Equals": [ true, false ] } }, + "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", "Resources": { - "explicithello2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "explicithello2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "explicithello2condition" - }, - "implicithello2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "implicithello2condition" - }, - "explicithello1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "explicithello1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "explicithello1condition" - }, - "explicitapiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "explicitapiDeploymentc8f1a3b6da" - }, - "RestApiId": { - "Ref": "explicitapi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment0270cbc16b" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "explicithello2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "explicithello2condition" - }, - "explicithello1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "explicithello1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "explicitapi" - } - } - ] - } - }, - "Condition": "explicithello1condition" - }, - "implicithello2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "implicithello2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "implicithello2condition" - }, - "implicithello1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "implicithello1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "implicithello1condition" - }, - "ServerlessRestApiDeployment0270cbc16b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 0270cbc16b8a9cded2c076b6ab6e50254430918b", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "implicithello1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "implicithello1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "implicithello1condition" - }, - "explicithello2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "explicithello2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "explicitapi" - } - } - ] - } - }, - "Condition": "explicithello2condition" - }, - "explicitapiDeploymentc8f1a3b6da": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "explicitapi" - }, - "Description": "RestApi deployment id: c8f1a3b6da24370ce143b6ab046e51dded1bfc36", - "StageName": "Stage" - } - }, - "explicitapi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/explicit/hello2": { + "/implicit/hello1": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { "get": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello2.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -358,30 +85,30 @@ } ] }, - "/explicit/hello1": { + "/implicit/hello2": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { "get": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello1.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -405,96 +132,67 @@ "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "implicithello2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ServerlessRestApiDeployment0270cbc16b": { + "Condition": "ServerlessRestApiCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "implicithello2" + "Description": "RestApi deployment id: 0270cbc16b8a9cded2c076b6ab6e50254430918b", + "RestApiId": { + "Ref": "ServerlessRestApi" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } + "StageName": "Stage" }, - "Condition": "implicithello2condition" + "Type": "AWS::ApiGateway::Deployment" }, - "explicithello1Role": { - "Type": "AWS::IAM::Role", + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment0270cbc16b" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" }, - "Condition": "explicithello1condition" + "Type": "AWS::ApiGateway::Stage" }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "explicitapi": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/implicit/hello1": { + "/explicit/hello1": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { "get": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello1.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -507,30 +205,30 @@ } ] }, - "/implicit/hello2": { + "/explicit/hello2": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { "get": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello2.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -555,22 +253,237 @@ "endpointConfigurationTypes": "REGIONAL" } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::ApiGateway::RestApi" }, - "implicithello1Role": { - "Type": "AWS::IAM::Role", + "explicitapiDeploymentc8f1a3b6da": { + "Properties": { + "Description": "RestApi deployment id: c8f1a3b6da24370ce143b6ab046e51dded1bfc36", + "RestApiId": { + "Ref": "explicitapi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "explicitapiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "explicitapiDeploymentc8f1a3b6da" + }, + "RestApiId": { + "Ref": "explicitapi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "explicithello1": { + "Condition": "explicithello1condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "explicithello1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "explicithello1ApiEventPermissionProd": { + "Condition": "explicithello1condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "explicithello1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello1", + { + "__ApiId__": { + "Ref": "explicitapi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "explicithello1Role": { + "Condition": "explicithello1condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "explicithello2": { + "Condition": "explicithello2condition", "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "explicithello2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "explicithello2ApiEventPermissionProd": { + "Condition": "explicithello2condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "explicithello2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello2", + { + "__ApiId__": { + "Ref": "explicitapi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "explicithello2Role": { + "Condition": "explicithello2condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "implicithello1": { + "Condition": "implicithello1condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "implicithello1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "implicithello1ApiEventPermissionProd": { + "Condition": "implicithello1condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "implicithello1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello1", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "implicithello1Role": { + "Condition": "implicithello1condition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -583,11 +496,98 @@ ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "implicithello2": { + "Condition": "implicithello2condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "implicithello2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "implicithello2ApiEventPermissionProd": { + "Condition": "implicithello2condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "implicithello2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello2", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } }, - "Condition": "implicithello1condition" + "Type": "AWS::Lambda::Permission" + }, + "implicithello2Role": { + "Condition": "implicithello2condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "A template to test for API condition handling with a mix of explicit and implicit api events." + } } diff --git a/tests/translator/output/aws-us-gov/implicit_api.json b/tests/translator/output/aws-us-gov/implicit_api.json index db1922ff59..e694b1c81f 100644 --- a/tests/translator/output/aws-us-gov/implicit_api.json +++ b/tests/translator/output/aws-us-gov/implicit_api.json @@ -1,292 +1,290 @@ { "Resources": { - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RestApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "RestApiFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "RestApiFunctionCompleteItemPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "GetHtmlFunction" - }, + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaaf8bd4588" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentaaf8bd4588": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aaf8bd4588f47e1167b22b3aadb5fdf6f2d306aa", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "RestApiFunctionGetListPermissionProd": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RestApiFunctionGetListPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/{proxy+}": { - "x-amazon-apigateway-any-method": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/complete": { - "post": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "RestApiFunctionCompleteItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaaf8bd4588": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: aaf8bd4588f47e1167b22b3aadb5fdf6f2d306aa", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaaf8bd4588" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/implicit_api_deletion_policy_precedence.json b/tests/translator/output/aws-us-gov/implicit_api_deletion_policy_precedence.json index 434cc36b0a..f50b409866 100644 --- a/tests/translator/output/aws-us-gov/implicit_api_deletion_policy_precedence.json +++ b/tests/translator/output/aws-us-gov/implicit_api_deletion_policy_precedence.json @@ -1,18 +1,16 @@ { "Resources": { - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", + "GetHtmlFunction": { + "DeletionPolicy": "Retain", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, - "Handler": "index.restapi", + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "GetHtmlFunctionRole", "Arn" ] }, @@ -23,15 +21,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function", + "UpdateReplacePolicy": "Retain" }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", + "GetHtmlFunctionGetHtmlPermissionProd": { + "DeletionPolicy": "Retain", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/{proxy++}", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission", + "UpdateReplacePolicy": "Retain" + }, + "GetHtmlFunctionRole": { + "DeletionPolicy": "Retain", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -44,11 +64,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" ], "Tags": [ { @@ -56,12 +77,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role", + "UpdateReplacePolicy": "Retain" + }, + "RestApiFunction": { + "DeletionPolicy": "Delete", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function", + "UpdateReplacePolicy": "Retain" }, "RestApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -79,40 +125,14 @@ } ] } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission", + "UpdateReplacePolicy": "Retain" }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", + "RestApiFunctionRole": { + "DeletionPolicy": "Delete", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -125,11 +145,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" ], "Tags": [ { @@ -137,97 +158,74 @@ "Value": "SAM" } ] - } - }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "GetHtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/{proxy++}", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/{proxy+}": { + "/{proxy++}": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/{proxy++}": { + "/{proxy+}": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - } + }, + "swagger": "2.0" }, "EndpointConfiguration": { "Types": [ - "REGIONAL" - ] + "REGIONAL" + ] }, "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "endpointConfigurationTypes": "REGIONAL" } - } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApiDeployment695a271271": { - "Type": "AWS::ApiGateway::Deployment", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "Description": "RestApi deployment id: 695a271271d114dfef4fba262c839d269473d910", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment695a271271" @@ -236,7 +234,9 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Retain" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/implicit_api_with_auth_and_conditions_max.json b/tests/translator/output/aws-us-gov/implicit_api_with_auth_and_conditions_max.json index 55919ab211..27e4888722 100644 --- a/tests/translator/output/aws-us-gov/implicit_api_with_auth_and_conditions_max.json +++ b/tests/translator/output/aws-us-gov/implicit_api_with_auth_and_conditions_max.json @@ -1,952 +1,952 @@ { "Conditions": { - "ServerlessRestApiCondition": { - "Fn::Or": [ - { - "Condition": "FunctionCondition" - }, - { - "Condition": "FunctionCondition2" - }, - { - "Condition": "FunctionCondition3" - }, - { - "Condition": "FunctionCondition4" - }, - { - "Condition": "FunctionCondition5" - }, - { - "Condition": "FunctionCondition6" - } + "FunctionCondition": { + "Fn::Equals": [ + true, + false ] - }, - "FunctionCondition6": { + }, + "FunctionCondition2": { "Fn::Equals": [ - true, + true, false ] - }, - "FunctionCondition5": { + }, + "FunctionCondition3": { "Fn::Equals": [ - true, + true, false ] - }, + }, "FunctionCondition4": { "Fn::Equals": [ - true, + true, false ] - }, - "FunctionCondition3": { + }, + "FunctionCondition5": { "Fn::Equals": [ - true, + true, false ] - }, - "FunctionCondition2": { + }, + "FunctionCondition6": { "Fn::Equals": [ - true, + true, false ] - }, - "ServerlessRestApiSLASHusersPathCondition": { + }, + "ServerlessRestApiCondition": { "Fn::Or": [ + { + "Condition": "FunctionCondition" + }, { "Condition": "FunctionCondition2" - }, + }, { "Condition": "FunctionCondition3" - }, + }, { "Condition": "FunctionCondition4" - }, + }, { "Condition": "FunctionCondition5" - }, + }, { "Condition": "FunctionCondition6" } ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - false + }, + "ServerlessRestApiSLASHusersPathCondition": { + "Fn::Or": [ + { + "Condition": "FunctionCondition2" + }, + { + "Condition": "FunctionCondition3" + }, + { + "Condition": "FunctionCondition4" + }, + { + "Condition": "FunctionCondition5" + }, + { + "Condition": "FunctionCondition6" + } ] } - }, + }, "Resources": { - "MyFunction4": { - "Type": "AWS::Lambda::Function", + "MyFunction": { + "Condition": "FunctionCondition", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction4Role", + "MyFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition4" - }, - "MyFunction6": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction2": { + "Condition": "FunctionCondition2", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction6Role", + "MyFunction2Role", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction2Role": { + "Condition": "FunctionCondition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition6" - }, + }, + "Type": "AWS::IAM::Role" + }, "MyFunction2WithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Condition": "FunctionCondition2", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyFunction2" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "FunctionCondition2" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyFunction3": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunction3Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "FunctionCondition3" - }, - "MyFunction2": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition3", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction2Role", + "MyFunction3Role", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition2" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment91a6380656" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "MyFunction5Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction3Role": { + "Condition": "FunctionCondition3", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "FunctionCondition5" - }, - "MyFunction2Role": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction3WithLambdaTokenAuthorizerPermissionProd": { + "Condition": "FunctionCondition3", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - }, - "Condition": "FunctionCondition2" - }, - "MyFunction4Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunction4": { + "Condition": "FunctionCondition4", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunction4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction4Role": { + "Condition": "FunctionCondition4", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction4WithLambdaTokenAuthorizerPermissionProd": { + "Condition": "FunctionCondition4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } - }, - "Condition": "FunctionCondition4" + }, + "Type": "AWS::Lambda::Permission" }, "MyFunction5": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition5", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction5Role", + "MyFunction5Role", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition5" - }, - "MyFunction6Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction5Role": { + "Condition": "FunctionCondition5", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "FunctionCondition6" - }, - "ServerlessRestApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "ServerlessRestApiCondition" - }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction5WithLambdaRequestAuthorizerPermissionProd": { + "Condition": "FunctionCondition5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunction" - }, + "Ref": "MyFunction5" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "FunctionCondition" + }, + "Type": "AWS::Lambda::Permission" }, - "MyFunction3Role": { - "Type": "AWS::IAM::Role", + "MyFunction6": { + "Condition": "FunctionCondition6", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunction6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction6Role": { + "Condition": "FunctionCondition6", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "FunctionCondition3" - }, - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition" - }, - "MyFunction4WithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction4" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition4" - }, - "ServerlessRestApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "ServerlessRestApiCondition" - }, - "MyFunction5WithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction6WithDefaultAuthorizerPermissionProd": { + "Condition": "FunctionCondition6", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunction5" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition5" - }, - "ServerlessRestApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", + "Ref": "MyFunction6" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", { "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "ServerlessRestApiCondition" + }, + "Type": "AWS::Lambda::Permission" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "FunctionCondition" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ServerlessRestApiDeployment91a6380656": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 91a63806562bbe4a3ad1c14c2444bc7d8d27397c", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "MyFunction3WithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition3" - }, - "MyFunction6WithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerPermissionProd": { + "Condition": "FunctionCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyFunction6" - }, + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "FunctionCondition6" - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "Fn::If": [ - "FunctionCondition", + "FunctionCondition", { "get": { "Fn::If": [ - "FunctionCondition", + "FunctionCondition", { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition", + "FunctionCondition", { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "NONE": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, + }, "/users": { "Fn::If": [ - "ServerlessRestApiSLASHusersPathCondition", + "ServerlessRestApiSLASHusersPathCondition", { - "put": { + "delete": { "Fn::If": [ - "FunctionCondition6", + "FunctionCondition5", { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition6", + "FunctionCondition5", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction6.Arn}/invocations" - }, + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction5.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "api_key": [] - }, - { - "MyCognitoAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, - "patch": { + }, + "get": { "Fn::If": [ - "FunctionCondition4", + "FunctionCondition3", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition4", + "FunctionCondition3", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction4.Arn}/invocations" - }, + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction3.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, - "post": { + }, + "patch": { "Fn::If": [ - "FunctionCondition2", + "FunctionCondition4", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition2", + "FunctionCondition4", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction2.Arn}/invocations" - }, + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction4.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyCognitoAuthMultipleUserPools": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, - "get": { + }, + "post": { "Fn::If": [ - "FunctionCondition3", + "FunctionCondition2", { + "responses": {}, + "security": [ + { + "MyCognitoAuthMultipleUserPools": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition3", + "FunctionCondition2", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction3.Arn}/invocations" - }, + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction2.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] - }, - "delete": { + }, + "put": { "Fn::If": [ - "FunctionCondition5", + "FunctionCondition6", { + "responses": {}, + "security": [ + { + "api_key": [] + }, + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition5", + "FunctionCondition6", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction5.Arn}/invocations" - }, + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction6.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "swagger": "2.0", + }, "securityDefinitions": { - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - } - }, + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, "x-amazon-apigateway-authtype": "custom" - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", + }, + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, + "authorizerResultTtlInSeconds": 0, "authorizerUri": { "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { "__FunctionArn__": "arn:aws" } ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, + }, + "type": "token" + }, "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": "2.0" + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - }, - "Condition": "ServerlessRestApiCondition" + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment91a6380656": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Description": "RestApi deployment id: 91a63806562bbe4a3ad1c14c2444bc7d8d27397c", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiMyLambdaRequestAuthAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiMyLambdaTokenAuthAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment91a6380656" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/implicit_api_with_many_conditions.json b/tests/translator/output/aws-us-gov/implicit_api_with_many_conditions.json index 7a98833719..43e7f8c687 100644 --- a/tests/translator/output/aws-us-gov/implicit_api_with_many_conditions.json +++ b/tests/translator/output/aws-us-gov/implicit_api_with_many_conditions.json @@ -1,49 +1,49 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "Cond5": { + "Cond": { "Fn::Equals": [ true, false ] }, - "Cond4": { + "Cond1": { "Fn::Equals": [ true, false ] }, - "Cond7": { + "Cond2": { "Fn::Equals": [ true, false ] }, - "Cond6": { + "Cond3": { "Fn::Equals": [ true, false ] }, - "Cond1": { + "Cond4": { "Fn::Equals": [ true, false ] }, - "Cond3": { + "Cond5": { "Fn::Equals": [ true, false ] }, - "Cond2": { + "Cond6": { "Fn::Equals": [ true, false ] }, - "Cond9": { + "Cond7": { "Fn::Equals": [ true, false @@ -55,7 +55,13 @@ false ] }, - "Cond": { + "Cond9": { + "Fn::Equals": [ + true, + false + ] + }, + "MyCondition": { "Fn::Equals": [ true, false @@ -105,12 +111,6 @@ } ] }, - "MyCondition": { - "Fn::Equals": [ - true, - false - ] - }, "ServerlessRestApiSLASHsubPathCondition": { "Fn::Or": [ { @@ -122,950 +122,69 @@ ] } }, + "Description": "A template to test for implicit API condition handling.", "Resources": { - "helloworld7ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld7" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond7" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment8fffc54734" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "helloworld1Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond1" - }, - "helloworld7": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld7Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond7" - }, - "helloworld6": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld6Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond6" - }, - "helloworldRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond" - }, - "helloworld4": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld4Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond4" - }, - "helloworld3": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld3Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond3" - }, - "helloworld2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond2" - }, - "helloworld1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond1" - }, - "helloworld9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld9Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond9" - }, - "helloApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "hello" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "MyCondition" - }, - "helloworld2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond2" - }, - "helloworld3ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond3" - }, - "helloworld1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond1" - }, - "helloworld8": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld8Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond8" - }, - "helloworld6ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld6" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond6" - }, - "helloworld4Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond4" - }, - "helloworldApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond" - }, - "helloworld9Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld5ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld5" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond5" - }, - "helloworld8ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld8" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond8" - }, - "helloRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "MyCondition" - }, - "helloworld8Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond8" - }, - "helloworld": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworldRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond" - }, - "helloworld5Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond5" - }, - "hello": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "MyCondition" - }, - "ServerlessRestApiDeployment8fffc54734": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 8fffc547345988f48beab2ad190a4c762fa2a92a", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "helloworld5": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld5Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond5" - }, - "helloworld9ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld9" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld6Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond6" - }, - "helloworld7Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond7" - }, - "helloworld2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond2" - }, - "helloworld3Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond3" - }, - "helloworld4ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld4" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond4" - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/sub": { "Fn::If": [ "ServerlessRestApiSLASHsubPathCondition", { - "post": { + "get": { "Fn::If": [ - "Cond", + "MyCondition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "MyCondition", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "get": { + "post": { "Fn::If": [ - "MyCondition", + "Cond", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "MyCondition", + "Cond", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1078,30 +197,30 @@ } ] }, - "/sub8": { + "/sub1": { "Fn::If": [ - "Cond8", + "Cond1", { "post": { "Fn::If": [ - "Cond8", + "Cond1", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond8", + "Cond1", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1114,30 +233,30 @@ } ] }, - "/sub9": { + "/sub2": { "Fn::If": [ - "Cond9", + "Cond2", { "post": { "Fn::If": [ - "Cond9", + "Cond2", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond9", + "Cond2", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1150,30 +269,30 @@ } ] }, - "/sub1": { + "/sub3": { "Fn::If": [ - "Cond1", + "Cond3", { "post": { "Fn::If": [ - "Cond1", + "Cond3", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond1", + "Cond3", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1186,30 +305,30 @@ } ] }, - "/sub2": { + "/sub4": { "Fn::If": [ - "Cond2", + "Cond4", { "post": { "Fn::If": [ - "Cond2", + "Cond4", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond2", + "Cond4", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1222,30 +341,30 @@ } ] }, - "/sub3": { + "/sub5": { "Fn::If": [ - "Cond3", + "Cond5", { "post": { "Fn::If": [ - "Cond3", + "Cond5", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond3", + "Cond5", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1258,30 +377,30 @@ } ] }, - "/sub4": { + "/sub6": { "Fn::If": [ - "Cond4", + "Cond6", { "post": { "Fn::If": [ - "Cond4", + "Cond6", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond4", + "Cond6", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1294,30 +413,30 @@ } ] }, - "/sub5": { + "/sub7": { "Fn::If": [ - "Cond5", + "Cond7", { "post": { "Fn::If": [ - "Cond5", + "Cond7", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond5", + "Cond7", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1330,30 +449,30 @@ } ] }, - "/sub6": { + "/sub8": { "Fn::If": [ - "Cond6", + "Cond8", { "post": { "Fn::If": [ - "Cond6", + "Cond8", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond6", + "Cond8", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1366,30 +485,30 @@ } ] }, - "/sub7": { + "/sub9": { "Fn::If": [ - "Cond7", + "Cond9", { "post": { "Fn::If": [ - "Cond7", + "Cond9", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond7", + "Cond9", { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1402,20 +521,901 @@ } ] } - }, - "swagger": "2.0" + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment8fffc54734": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Description": "RestApi deployment id: 8fffc547345988f48beab2ad190a4c762fa2a92a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment8fffc54734" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "hello": { + "Condition": "MyCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloApiEventPermissionProd": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "hello" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloRole": { + "Condition": "MyCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld": { + "Condition": "Cond", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworldRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1": { + "Condition": "Cond1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1ApiEventPermissionProd": { + "Condition": "Cond1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1Role": { + "Condition": "Cond1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld2": { + "Condition": "Cond2", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld2ApiEventPermissionProd": { + "Condition": "Cond2", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld2Role": { + "Condition": "Cond2", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld3": { + "Condition": "Cond3", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld3Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld3ApiEventPermissionProd": { + "Condition": "Cond3", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld3Role": { + "Condition": "Cond3", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld4": { + "Condition": "Cond4", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld4ApiEventPermissionProd": { + "Condition": "Cond4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld4Role": { + "Condition": "Cond4", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld5": { + "Condition": "Cond5", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld5Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld5ApiEventPermissionProd": { + "Condition": "Cond5", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld5" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld5Role": { + "Condition": "Cond5", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld6": { + "Condition": "Cond6", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld6ApiEventPermissionProd": { + "Condition": "Cond6", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld6" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld6Role": { + "Condition": "Cond6", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld7": { + "Condition": "Cond7", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld7Role", + "Arn" ] }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld7ApiEventPermissionProd": { + "Condition": "Cond7", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld7" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld7Role": { + "Condition": "Cond7", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld8": { + "Condition": "Cond8", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld8Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld8ApiEventPermissionProd": { + "Condition": "Cond8", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld8" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" + }, + "helloworld8Role": { + "Condition": "Cond8", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld9": { + "Condition": "Cond9", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld9Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld9ApiEventPermissionProd": { + "Condition": "Cond9", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld9" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld9Role": { + "Condition": "Cond9", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworldApiEventPermissionProd": { + "Condition": "Cond", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworldRole": { + "Condition": "Cond", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "A template to test for implicit API condition handling." + } } diff --git a/tests/translator/output/aws-us-gov/implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/aws-us-gov/implicit_api_with_serverless_rest_api_resource.json index fa2d5021dd..e694b1c81f 100644 --- a/tests/translator/output/aws-us-gov/implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/aws-us-gov/implicit_api_with_serverless_rest_api_resource.json @@ -1,290 +1,290 @@ { "Resources": { - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RestApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "RestApiFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "RestApiFunctionCompleteItemPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "GetHtmlFunction" - }, + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaaf8bd4588" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeploymentaaf8bd4588": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aaf8bd4588f47e1167b22b3aadb5fdf6f2d306aa", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "RestApiFunctionGetListPermissionProd": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RestApiFunctionGetListPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/{proxy+}": { - "x-amazon-apigateway-any-method": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, - "/complete": { - "post": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" - }, + }, "EndpointConfiguration": { "Types": [ "REGIONAL" ] - }, + }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } - } - }, - "RestApiFunctionCompleteItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaaf8bd4588": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: aaf8bd4588f47e1167b22b3aadb5fdf6f2d306aa", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaaf8bd4588" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/aws-us-gov/implicit_http_api.json b/tests/translator/output/aws-us-gov/implicit_http_api.json index 713e890c64..41977546b5 100644 --- a/tests/translator/output/aws-us-gov/implicit_http_api.json +++ b/tests/translator/output/aws-us-gov/implicit_http_api.json @@ -1,275 +1,275 @@ { "Resources": { - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "HttpApiFunction": { "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunction2": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunction2Basic2Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/basic2", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] } - } - }, - "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HttpApiFunction2PathParametersPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HttpApiFunction2Role": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunction2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "HttpApiFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic2": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } - }, - "/get/{something}/with/{params}": { + }, + "/basic": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {}, - "parameters": [ - { - "required": true, - "name": "something", - "in": "path" - }, - { - "required": true, - "name": "params", - "in": "path" + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - ] + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/basic2": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" + } + } } - }, - "/basic": { + }, + "/get/{something}/with/{params}": { "post": { + "parameters": [ + { + "in": "path", + "name": "something", + "required": true + }, + { + "in": "path", + "name": "params", + "required": true + } + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" + } + } } } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } - }, - "HttpApiFunction2PathParametersPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - } - }, - "HttpApiFunction2Basic2Permission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/basic2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/implicit_http_api_auth_and_simple_case.json b/tests/translator/output/aws-us-gov/implicit_http_api_auth_and_simple_case.json index 7ace3a5224..180a7ed2ed 100644 --- a/tests/translator/output/aws-us-gov/implicit_http_api_auth_and_simple_case.json +++ b/tests/translator/output/aws-us-gov/implicit_http_api_auth_and_simple_case.json @@ -1,230 +1,230 @@ { "Resources": { - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "RestApiFunction": { "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/defaultauth": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - }, - "/oauth2": { - "post": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + } + } + } + }, + "/defaultauth": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + } + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/noneauth": { + "post": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, + } + } + } + }, + "/oauth2": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - }, - "/noneauth": { - "post": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "NONE": [] } - ], - "responses": {} + } } - }, + }, "/scope3": { "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + "responses": {}, "security": [ { "oauth2Auth": [ "scope3" ] } - ], - "responses": {} - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } } } } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/implicit_http_api_with_many_conditions.json b/tests/translator/output/aws-us-gov/implicit_http_api_with_many_conditions.json index 9f11855958..75d8457fbd 100644 --- a/tests/translator/output/aws-us-gov/implicit_http_api_with_many_conditions.json +++ b/tests/translator/output/aws-us-gov/implicit_http_api_with_many_conditions.json @@ -1,1506 +1,1506 @@ { - "AWSTemplateFormatVersion": "2010-09-09", + "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "Cond5": { + "Cond": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond4": { + }, + "Cond1": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond7": { + }, + "Cond2": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond6": { + }, + "Cond3": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond1": { + }, + "Cond4": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond3": { + }, + "Cond5": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond2": { + }, + "Cond6": { "Fn::Equals": [ - true, + true, false ] - }, - "ServerlessHttpApiCondition": { - "Fn::Or": [ - { - "Condition": "MyCondition" - }, - { - "Condition": "ServerlessHttpApiCondition1" - } - ] - }, - "Cond9": { + }, + "Cond7": { "Fn::Equals": [ - true, + true, false ] - }, + }, "Cond8": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond": { + }, + "Cond9": { + "Fn::Equals": [ + true, + false + ] + }, + "MyCondition": { "Fn::Equals": [ - true, + true, false ] - }, + }, + "ServerlessHttpApiCondition": { + "Fn::Or": [ + { + "Condition": "MyCondition" + }, + { + "Condition": "ServerlessHttpApiCondition1" + } + ] + }, "ServerlessHttpApiCondition1": { "Fn::Or": [ { "Condition": "Cond" - }, + }, { "Condition": "Cond1" - }, + }, { "Condition": "Cond2" - }, + }, { "Condition": "Cond3" - }, + }, { "Condition": "Cond4" - }, + }, { "Condition": "Cond5" - }, + }, { "Condition": "Cond6" - }, + }, { "Condition": "Cond7" - }, + }, { "Condition": "Cond8" - }, + }, { "Condition": "Cond9" } ] - }, - "MyCondition": { - "Fn::Equals": [ - true, - false - ] } - }, - "Description": "A template to test for implicit HttpApi condition handling.", + }, + "Description": "A template to test for implicit HttpApi condition handling.", "Resources": { - "helloworld9HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld9" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld9Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "Cond9" - }, - "helloworld2HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond2" - }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", + "Condition": "ServerlessHttpApiCondition", "Properties": { "Body": { + "components": { + "securitySchemes": { + "oauth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/hello/again": { + "$default": { "Fn::If": [ - "Cond", + "Cond", { - "get": { + "x-amazon-apigateway-any-method": { "Fn::If": [ - "Cond", + "Cond", { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "oauth2": [ + "scope4" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "Cond", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub": { + }, + "/hello/again": { "Fn::If": [ - "MyCondition", + "Cond", { "get": { "Fn::If": [ - "MyCondition", + "Cond", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "MyCondition", + "Cond", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub8": { + }, + "/sub": { "Fn::If": [ - "Cond8", + "MyCondition", { - "post": { + "get": { "Fn::If": [ - "Cond8", + "MyCondition", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond8", + "MyCondition", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub9": { + }, + "/sub1": { "Fn::If": [ - "Cond9", + "Cond1", { "post": { "Fn::If": [ - "Cond9", + "Cond1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond9", + "Cond1", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "$default": { + }, + "/sub2": { "Fn::If": [ - "Cond", + "Cond2", { - "x-amazon-apigateway-any-method": { + "post": { "Fn::If": [ - "Cond", + "Cond2", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "Cond2", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "security": [ - { - "oauth2": [ - "scope4" - ] } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub1": { + }, + "/sub3": { "Fn::If": [ - "Cond1", + "Cond3", { "post": { "Fn::If": [ - "Cond1", + "Cond3", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond1", + "Cond3", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub2": { + }, + "/sub4": { "Fn::If": [ - "Cond2", + "Cond4", { "post": { "Fn::If": [ - "Cond2", + "Cond4", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond2", + "Cond4", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub3": { + }, + "/sub5": { "Fn::If": [ - "Cond3", + "Cond5", { "post": { "Fn::If": [ - "Cond3", + "Cond5", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond3", + "Cond5", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub4": { + }, + "/sub6": { "Fn::If": [ - "Cond4", + "Cond6", { "post": { "Fn::If": [ - "Cond4", + "Cond6", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond4", + "Cond6", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub5": { + }, + "/sub7": { "Fn::If": [ - "Cond5", + "Cond7", { "post": { "Fn::If": [ - "Cond5", + "Cond7", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond5", + "Cond7", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub6": { + }, + "/sub8": { "Fn::If": [ - "Cond6", + "Cond8", { "post": { "Fn::If": [ - "Cond6", + "Cond8", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond6", + "Cond8", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub7": { + }, + "/sub9": { "Fn::If": [ - "Cond7", + "Cond9", { "post": { "Fn::If": [ - "Cond7", + "Cond9", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond7", + "Cond9", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - } - } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - }, - "Condition": "ServerlessHttpApiCondition" - }, - "helloworld6HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Condition": "ServerlessHttpApiCondition", + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "RouteSettings": { + "$default": { + "Fn::If": [ + "Cond", + { + "ThrottlingBurstLimit": 200 + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "GET /sub": { + "Fn::If": [ + "MyCondition", + { + "ThrottlingBurstLimit": 200 + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "hello": { + "Condition": "MyCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloHttpApiEventPermission": { + "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld6" - }, + "Ref": "hello" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond6" - }, - "helloworld1Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloRole": { + "Condition": "MyCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond1" - }, - "helloworld7": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld1": { + "Condition": "Cond1", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld7Role", + "helloworld1Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond7" - }, - "helloworld6": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld6Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond6" - }, - "helloworld5": { - "Type": "AWS::Lambda::Function", + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1099": { + "Condition": "Cond", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld5Role", + "helloworld1099Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond5" - }, - "helloworld1099Role": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1099HttpApiEventPermission": { + "Condition": "Cond", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1099" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1099Role": { + "Condition": "Cond", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond" - }, - "helloworld3": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld1HttpApiEventPermission": { + "Condition": "Cond1", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld3Role", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond3" - }, - "helloworld2": { - "Type": "AWS::Lambda::Function", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1Role": { + "Condition": "Cond1", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond2" - }, - "helloworld1": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld2": { + "Condition": "Cond2", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld1Role", + "helloworld2Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond1" - }, - "helloworld9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld9Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond9" - }, - "hello": { - "Type": "AWS::Lambda::Function", + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld2HttpApiEventPermission": { + "Condition": "Cond2", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "MyCondition" - }, - "helloRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld2Role": { + "Condition": "Cond2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "MyCondition" - }, - "helloworld7HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld7" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond7" - }, - "helloHttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld3": { + "Condition": "Cond3", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "hello" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld3Role", + "Arn" ] - } - }, - "Condition": "MyCondition" - }, - "helloworld1HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld3HttpApiEventPermission": { + "Condition": "Cond3", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld1" - }, + "Ref": "helloworld3" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond1" - }, - "helloworld5Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld3Role": { + "Condition": "Cond3", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond5" - }, + }, + "Type": "AWS::IAM::Role" + }, + "helloworld4": { + "Condition": "Cond4", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld4HttpApiEventPermission": { + "Condition": "Cond4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "helloworld4Role": { - "Type": "AWS::IAM::Role", + "Condition": "Cond4", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond4" - }, - "helloworld1099HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld5": { + "Condition": "Cond5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld1099" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld5Role", + "Arn" ] - } - }, - "Condition": "Cond" - }, + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "helloworld5HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "Cond5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "helloworld5" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond5" - }, - "helloworld7Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld5Role": { + "Condition": "Cond5", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond7" - }, - "helloworld2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld6": { + "Condition": "Cond6", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld6HttpApiEventPermission": { + "Condition": "Cond6", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld6" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld6Role": { + "Condition": "Cond6", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond2" - }, - "helloworld8Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld7": { + "Condition": "Cond7", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld7Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld7HttpApiEventPermission": { + "Condition": "Cond7", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld7" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld7Role": { + "Condition": "Cond7", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond8" - }, - "helloworld4": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld8": { + "Condition": "Cond8", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld4Role", + "helloworld8Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond4" - }, - "helloworld1099": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld1099Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond" - }, + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "helloworld8HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "Cond8", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "helloworld8" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond8" - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "RouteSettings": { - "GET /sub": { - "Fn::If": [ - "MyCondition", - { - "ThrottlingBurstLimit": 200 - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "$default": { - "Fn::If": [ - "Cond", - { - "ThrottlingBurstLimit": 200 - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "ServerlessHttpApiCondition" - }, - "helloworld3Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld8Role": { + "Condition": "Cond8", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond3" - }, - "helloworld8": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld9": { + "Condition": "Cond9", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld8Role", + "helloworld9Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond8" - }, - "helloworld4HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld9HttpApiEventPermission": { + "Condition": "Cond9", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld4" - }, + "Ref": "helloworld9" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond4" - }, - "helloworld6Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld9Role": { + "Condition": "Cond9", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond6" - }, - "helloworld3HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond3" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/inline_precedence.json b/tests/translator/output/aws-us-gov/inline_precedence.json index 7d650c33ae..8e94957b43 100644 --- a/tests/translator/output/aws-us-gov/inline_precedence.json +++ b/tests/translator/output/aws-us-gov/inline_precedence.json @@ -1,56 +1,56 @@ { - "Resources": { - "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "Resources": { + "HelloWorldFunction": { + "Properties": { + "Code": { + "ZipFile": "\"def lambda_handler():\n pass\"\n" + }, + "Handler": "index.lambda_handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.8", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.lambda_handler", - "Code": { - "ZipFile": "\"def lambda_handler():\n pass\"\n" - }, - "Role": { - "Fn::GetAtt": [ - "HelloWorldFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.8", - "Tags": [ + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/intrinsic_functions.json b/tests/translator/output/aws-us-gov/intrinsic_functions.json index 3a87a501db..b2b44466be 100644 --- a/tests/translator/output/aws-us-gov/intrinsic_functions.json +++ b/tests/translator/output/aws-us-gov/intrinsic_functions.json @@ -8,14 +8,14 @@ } }, "Parameters": { - "CodeKey": { - "Default": "key", - "Type": "String" - }, "CodeBucket": { "Default": "sam-demo-bucket", "Type": "String" }, + "CodeKey": { + "Default": "key", + "Type": "String" + }, "FunctionName": { "Default": "MySuperFunctionName", "Type": "String" @@ -24,181 +24,114 @@ "Default": "SomeName", "Type": "String" }, + "RoleFieldName": { + "Default": "Role", + "Type": "String" + }, "TracingConfigParam": { "Default": "PassThrough", "Type": "String" - }, - "RoleFieldName": { - "Type": "String", - "Default": "Role" } }, "Resources": { - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "ApiWithExplicitS3Uri": { + "Condition": "TrueCondition", "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } - }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, - "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "DeadLetterConfig": { - "TargetArn": { - "Fn::GetAtt": [ - "SqsDlqQueue", - "Arn" - ] - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", - "Arn" - ] + "Bucket": "mybucket", + "Key": "mykey", + "Version": 3 }, - "Runtime": "python2.7" - } - }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { "EndpointConfiguration": { "Types": [ "REGIONAL" ] }, - "BodyS3Location": { - "Version": "myversion", - "Bucket": "mybucket", - "Key": "mykey" - }, "Parameters": { "endpointConfigurationTypes": "REGIONAL" } }, - "Condition": "TrueCondition" + "Type": "AWS::ApiGateway::RestApi" }, - "MyExplicitApiDeployment7145dd00ce": { - "Type": "AWS::ApiGateway::Deployment", + "ApiWithExplicitS3UriDeployment7ab7044581": { + "Condition": "TrueCondition", "Properties": { + "Description": "RestApi deployment id: 7ab7044581d53db4957e668f336b462f099db4af", "RestApiId": { - "Ref": "MyExplicitApi" + "Ref": "ApiWithExplicitS3Uri" }, - "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "ApiWithExplicitS3UridevStage": { + "Condition": "TrueCondition", + "Properties": { + "DeploymentId": { + "Ref": "ApiWithExplicitS3UriDeployment7ab7044581" + }, + "RestApiId": { + "Ref": "ApiWithExplicitS3Uri" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "DynamoDBFunction": { "Properties": { - "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" }, + "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", + "DynamoDBFunctionRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "DynamoDBFunctionMyDDBStream": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Ref": "SnsDlqQueue" - }, - "Effect": "Allow" + "BatchSize": 200, + "EventSourceArn": { + "Fn::GetAtt": [ + "MyTable", + "StreamArn" + ] + }, + "FilterCriteria": { + "Fn::Select": [ + "1", + [ + {}, + { + "Filters": { + "Pattern": "{\"value\": \"b\"}" } - ] - } - } - ], + } + ] + ] + }, + "FunctionName": { + "Ref": "DynamoDBFunction" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "DynamoDBFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -211,21 +144,33 @@ ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyOtherFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithExplicitS3Uri": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "S3Bucket": "mybucket", + "S3Key": "mykey", + "S3ObjectVersion": "MyVersion" }, - "Handler": "hello.handler", + "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ - "MyOtherFunctionRole", + "FunctionWithExplicitS3UriRole", "Arn" ] }, @@ -236,13 +181,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyOtherFunctionRole": { - "Type": "AWS::IAM::Role", + "FunctionWithExplicitS3UriRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -255,7 +199,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -266,10 +211,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "FunctionWithValidGetAttAndRef": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -291,16 +236,67 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunction": { - "Type": "AWS::Lambda::Function", + "MyExplicitApi": { "Properties": { - "TracingConfig": { - "Mode": { - "Ref": "TracingConfigParam" - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "swagger.yaml" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Name": { + "Ref": "MyExplicitApiName" + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyExplicitApiDeployment7145dd00ce": { + "Properties": { + "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyExplicitApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyExplicitApiDeployment7145dd00ce" + }, + "RestApiId": { + "Ref": "MyExplicitApi" }, + "StageName": "dev", + "Variables": { + "FunctionName": { + "Fn::Sub": "${MyFunction}" + }, + "Var2": { + "Fn::Join": [ + "join ", + [ + "some value ", + "with some other value" + ] + ] + } + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { "Code": { "S3Bucket": { "Ref": "CodeBucket" @@ -321,12 +317,6 @@ "FunctionName": { "Fn::Sub": "${FunctionName}" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": { "Fn::Sub": [ "${filename}.handler", @@ -349,14 +339,45 @@ "4.3" ] ] + }, + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "TracingConfig": { + "Mode": { + "Ref": "TracingConfigParam" + } } - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithExplicitS3UriRole": { - "Type": "AWS::IAM::Role", + "MyFunctionMyApiPermissiondev": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyNewRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -369,48 +390,56 @@ ] } } - ] + ], + "Version": "2012-10-17" }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "cloudwatch:*", + "logs:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "lambdaRole" } ] - } - }, - "ApiWithExplicitS3UriDeployment7ab7044581": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: 7ab7044581d53db4957e668f336b462f099db4af", - "StageName": "Stage" }, - "Condition": "TrueCondition" + "Type": "AWS::IAM::Role" }, - "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", + "MyOtherFunction": { "Properties": { - "DeploymentId": { - "Ref": "ApiWithExplicitS3UriDeployment7ab7044581" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyOtherFunctionRole", + "Arn" + ] }, - "StageName": "dev" + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "TrueCondition" + "Type": "AWS::Lambda::Function" }, - "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", + "MyOtherFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -423,22 +452,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -449,12 +478,6 @@ "Ref": "SnsDlqQueue" } }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -462,81 +485,64 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "MySnsDlqLambdaFunctionRole": { "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "Policies": [ { - "AttributeName": "id", - "AttributeType": "S" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": { + "Ref": "SnsDlqQueue" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } - }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, - "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "stream.ddb_handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Role": { - "Fn::GetAtt": [ - "DynamoDBFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -550,12 +556,6 @@ ] } }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -563,125 +563,19 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyExplicitApiDeployment7145dd00ce" - }, - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "Variables": { - "FunctionName": { - "Fn::Sub": "${MyFunction}" - }, - "Var2": { - "Fn::Join": [ - "join ", - [ - "some value ", - "with some other value" - ] - ] - } - }, - "StageName": "dev" - } - }, - "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 200, - "FunctionName": { - "Ref": "DynamoDBFunction" - }, - "StartingPosition": "LATEST", - "EventSourceArn": { - "Fn::GetAtt": [ - "MyTable", - "StreamArn" - ] - }, - "FilterCriteria": { - "Fn::Select": [ - "1", - [ - {}, - { - "Filters": { - "Pattern": "{\"value\": \"b\"}" - } - } - ] - ] - } - } - }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "stream.ddb_handler", - "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", - "Arn" - ] - }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyExplicitApiDeployment7145dd00ce": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", - "StageName": "Stage" - } - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "BodyS3Location": { - "Version": 3, - "Bucket": "mybucket", - "Key": "mykey" - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } }, - "Condition": "TrueCondition" + "Type": "AWS::Lambda::Function" }, "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -694,145 +588,70 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ "SqsDlqQueue", "Arn" ] - }, - "Effect": "Allow" + } } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "MyTable": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ + "AttributeDefinitions": [ { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Ref": "SnsDlqQueue" - }, - "Effect": "Allow" - } - ] - } + "AttributeName": "id", + "AttributeType": "S" } ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyNewRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + "KeySchema": [ { - "PolicyName": "lambdaRole", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "cloudwatch:*", - "logs:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } + "AttributeName": "id", + "KeyType": "HASH" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyExplicitApi" - } - } - ] + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" } - } + }, + "Type": "AWS::DynamoDB::Table" + }, + "SnsDlqQueue": { + "Type": "AWS::SNS::Topic" + }, + "SqsDlqQueue": { + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/iot_rule.json b/tests/translator/output/aws-us-gov/iot_rule.json index e648ef60da..069117fcd5 100644 --- a/tests/translator/output/aws-us-gov/iot_rule.json +++ b/tests/translator/output/aws-us-gov/iot_rule.json @@ -1,31 +1,79 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, "Resources": { + "IoTRuleFunc": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "IoTRuleFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "IoTRuleFuncMyIoTRule": { - "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { - "AwsIotSqlVersion": "beta", "Actions": [ { "Lambda": { "FunctionArn": { "Fn::GetAtt": [ - "IoTRuleFunc", + "IoTRuleFunc", "Arn" ] } } } - ], - "RuleDisabled": false, + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, "Sql": "SELECT * FROM 'topic/test'" } - } - }, + }, + "Type": "AWS::IoT::TopicRule" + }, + "IoTRuleFuncMyIoTRulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "IoTRuleFunc" + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + { + "RuleName": { + "Ref": "IoTRuleFuncMyIoTRule" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "IoTRuleFuncMyOtherIoTRule": { - "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { "Actions": [ @@ -33,52 +81,29 @@ "Lambda": { "FunctionArn": { "Fn::GetAtt": [ - "IoTRuleFunc", + "IoTRuleFunc", "Arn" ] } } } - ], - "RuleDisabled": false, + ], + "RuleDisabled": false, "Sql": "SELECT * FROM 'topic/test'" } - } - }, - "IoTRuleFuncMyIoTRulePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IoT::TopicRule" + }, + "IoTRuleFuncMyOtherIoTRulePermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "IoTRuleFunc" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", - { - "RuleName": { - "Ref": "IoTRuleFuncMyIoTRule" - } - } - ] - } - } - }, - "IoTRuleFuncMyOtherIoTRulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", + }, + "Principal": "iot.amazonaws.com", "SourceAccount": { "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", - "FunctionName": { - "Ref": "IoTRuleFunc" - }, + }, "SourceArn": { "Fn::Sub": [ "arn:aws-us-gov:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", @@ -89,63 +114,38 @@ } ] } - } - }, - "IoTRuleFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "IoTRuleFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "IoTRuleFuncRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/kinesis_intrinsics.json b/tests/translator/output/aws-us-gov/kinesis_intrinsics.json index a3490c2797..771334344c 100644 --- a/tests/translator/output/aws-us-gov/kinesis_intrinsics.json +++ b/tests/translator/output/aws-us-gov/kinesis_intrinsics.json @@ -1,168 +1,168 @@ { - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + }, + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "FunctionResponseTypesValue": { + "Default": "ReportBatchItemFailures", + "Type": "String" + }, + "IntValue": { + "Default": 50, + "Type": "Number" + }, + "StartingPositionValue": { + "Default": "LATEST", + "Type": "String" + }, + "StringValue": { + "Default": "us-east-1", + "Type": "String" + } + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "stream.zip" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] - } - }, - "Resources": { - "MyLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionKinesisStream": { + "Properties": { + "BatchSize": { + "Ref": "IntValue" + }, + "BisectBatchOnFunctionError": { + "Fn::If": [ + "FalseCondition", + true, + false + ] + }, + "Enabled": { + "Fn::If": [ + "TrueCondition", + true, + false + ] + }, + "EventSourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":kinesis:", + { + "Ref": "AWS::Region" + }, + ":", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "Ref": "AWS::AccountId" + }, + ":stream/", + { + "Ref": "MyStream" } ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } ] - } - }, - "MyLambdaFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "IntValue" - }, - "FunctionName": { - "Ref": "MyLambdaFunction" - }, - "MaximumRecordAgeInSeconds": { - "Ref": "IntValue" - }, - "FunctionResponseTypes": [ - { - "Ref": "FunctionResponseTypesValue" - } - ], - "BatchSize": { - "Ref": "IntValue" - }, - "TumblingWindowInSeconds": { - "Ref": "IntValue" - }, - "Enabled": { - "Fn::If": [ - "TrueCondition", - true, - false - ] - }, - "EventSourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":kinesis:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":stream/", - { - "Ref": "MyStream" - } - ] - ] - }, - "StartingPosition": { - "Ref": "StartingPositionValue" - }, - "ParallelizationFactor": { - "Ref": "IntValue" - }, - "MaximumRetryAttempts": { - "Ref": "IntValue" - }, - "BisectBatchOnFunctionError": { - "Fn::If": [ - "FalseCondition", - true, - false - ] + }, + "FunctionName": { + "Ref": "MyLambdaFunction" + }, + "FunctionResponseTypes": [ + { + "Ref": "FunctionResponseTypesValue" } + ], + "MaximumBatchingWindowInSeconds": { + "Ref": "IntValue" + }, + "MaximumRecordAgeInSeconds": { + "Ref": "IntValue" + }, + "MaximumRetryAttempts": { + "Ref": "IntValue" + }, + "ParallelizationFactor": { + "Ref": "IntValue" + }, + "StartingPosition": { + "Ref": "StartingPositionValue" + }, + "TumblingWindowInSeconds": { + "Ref": "IntValue" } - }, - "MyStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } - }, - "MyLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "stream.zip" - }, - "Tags": [ + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - } - }, - "Parameters": { - "StringValue": { - "Default": "us-east-1", - "Type": "String" - }, - "IntValue": { - "Default": 50, - "Type": "Number" - }, - "FunctionResponseTypesValue": { - "Default": "ReportBatchItemFailures", - "Type": "String" - }, - "StartingPositionValue": { - "Default": "LATEST", - "Type": "String" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/layer_deletion_policy_precedence.json b/tests/translator/output/aws-us-gov/layer_deletion_policy_precedence.json index 8bb610ad00..f2b1de47a4 100644 --- a/tests/translator/output/aws-us-gov/layer_deletion_policy_precedence.json +++ b/tests/translator/output/aws-us-gov/layer_deletion_policy_precedence.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalLayer22b6609c3d": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Retain", "Properties": { "Content": { @@ -9,10 +8,10 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer" - } + }, + "Type": "AWS::Lambda::LayerVersion" }, "MinimalLayer2800a44a445": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Delete", "Properties": { "Content": { @@ -20,10 +19,10 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer2" - } + }, + "Type": "AWS::Lambda::LayerVersion" }, "MinimalLayer3ac07350a04": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Retain", "Properties": { "Content": { @@ -31,7 +30,8 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer3" - } + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/layers_all_properties.json b/tests/translator/output/aws-us-gov/layers_all_properties.json index 066c5eaab8..f3cb751db3 100644 --- a/tests/translator/output/aws-us-gov/layers_all_properties.json +++ b/tests/translator/output/aws-us-gov/layers_all_properties.json @@ -1,120 +1,120 @@ { "Outputs": { - "LayerSub": { - "Value": { - "Fn::Sub": "${MyLayerd04062b365}" - } - }, "FunctionAtt": { "Value": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] } - }, - "LayerName": { + }, + "FunctionName": { "Value": { - "Ref": "MyLayerd04062b365" + "Ref": "MyFunction" } - }, + }, "FunctionSub": { "Value": { "Fn::Sub": "${MyFunction}" } - }, - "FunctionName": { + }, + "LayerName": { "Value": { - "Ref": "MyFunction" + "Ref": "MyLayerd04062b365" + } + }, + "LayerSub": { + "Value": { + "Fn::Sub": "${MyLayerd04062b365}" } } - }, + }, "Parameters": { "LayerDeleteParam": { - "Default": "Delete", + "Default": "Delete", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Layers": [ - { - "Ref": "MyLayerd04062b365" - } - ], "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, - "Tags": [ + }, + "Handler": "app.handler", + "Layers": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "MyLayerd04062b365" } - ], - "Handler": "app.handler", + ], "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python3.6" - } - }, - "MyLayerd04062b365": { - "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "MyLayer" - } - }, - "MyLayerWithANamefda8c9ec8c": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "DifferentLayerName" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayerWithANamefda8c9ec8c": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "DifferentLayerName" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "MyLayerd04062b365": { + "DeletionPolicy": "Delete", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json index 48de0c3856..06277c85a6 100644 --- a/tests/translator/output/aws-us-gov/layers_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/layers_with_intrinsics.json @@ -1,167 +1,166 @@ { "Parameters": { "CompatibleArchitecturesList": { - "Type": "CommaDelimitedList", - "Default": "arm64,x86_64" + "Default": "arm64,x86_64", + "Type": "CommaDelimitedList" }, "CompatibleArchitecturesRef": { - "Type": "String", - "Default": "arm64" + "Default": "arm64", + "Type": "String" }, "LayerLicenseInfo": { "Default": "MIT-0 License", "Type": "String" }, - "LayerRuntimeList": { - "Type": "CommaDelimitedList" - }, "LayerNameParam": { "Default": "SomeLayerName", "Type": "String" }, + "LayerRuntimeList": { + "Type": "CommaDelimitedList" + }, "LayerRuntimeRefString": { "Default": "SomeRuntimeName", "Type": "String" } }, "Resources": { - "LayerWithNameIntrinsiccf8baed8b9": { + "LayerWithArchitecturesIntrinsicb79067ee69": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleArchitectures": { + "Ref": "CompatibleArchitecturesList" + }, "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "SomeLayerName" - } + "LayerName": "LayerWithArchitecturesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithRefNameIntrinsicRegionad31c93c8b": { + "LayerWithLicenseIntrinsic965c8d0c9b": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "us-gov-west-1" - } + "LayerName": "LayerWithLicenseIntrinsic", + "LicenseInfo": "MIT-0 License" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSubNameIntrinsicRegion5b2c74d55e": { + "LayerWithMixedListRefRuntimesIntrinsic71fd80f592": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleRuntimes": [ + { + "Ref": "LayerRuntimeString" + }, + "SomeRuntimeNameString" + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": { - "Fn::Sub": "layer-us-gov-west-1" - } - } + "LayerName": "LayerWithMixedListRefRuntimesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithRuntimesIntrinsic1a006faa85": { + "LayerWithNameIntrinsiccf8baed8b9": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesIntrinsic", - "CompatibleRuntimes": { - "Ref": "LayerRuntimeList" - } - } + "LayerName": "SomeLayerName" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": { + "LayerWithRefNameIntrinsicRegionad31c93c8b": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleRuntimes": [ - { - "Ref": "LayerRuntimeRefString" - } - ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithSingleListRefRuntimesIntrinsic" + "LayerName": "us-gov-west-1" }, "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithMixedListRefRuntimesIntrinsic71fd80f592": { + "LayerWithRuntimesIntrinsic1a006faa85": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleRuntimes": [ - { - "Ref": "LayerRuntimeString" - }, - "SomeRuntimeNameString" - ], + "CompatibleRuntimes": { + "Ref": "LayerRuntimeList" + }, "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithMixedListRefRuntimesIntrinsic" + "LayerName": "LayerWithRuntimesIntrinsic" }, "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithLicenseIntrinsic965c8d0c9b": { + "LayerWithSingleListRefArchitecturesIntrinsicf8a2807636": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleArchitectures": [ + { + "Ref": "CompatibleArchitecturesRef" + } + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithLicenseIntrinsic", - "LicenseInfo": "MIT-0 License" - } + "LayerName": "LayerWithSingleListRefArchitecturesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSubNameIntrinsic6e9b477102": { - "Type": "AWS::Lambda::LayerVersion", + "LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": { "DeletionPolicy": "Retain", "Properties": { + "CompatibleRuntimes": [ + { + "Ref": "LayerRuntimeRefString" + } + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": { - "Fn::Sub": "layer-SomeLayerName" - } - } + "LayerName": "LayerWithSingleListRefRuntimesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithArchitecturesIntrinsicb79067ee69": { + "LayerWithSubNameIntrinsic6e9b477102": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithArchitecturesIntrinsic", - "CompatibleArchitectures": { - "Ref": "CompatibleArchitecturesList" + "LayerName": { + "Fn::Sub": "layer-SomeLayerName" } - } + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSingleListRefArchitecturesIntrinsicf8a2807636": { + "LayerWithSubNameIntrinsicRegion5b2c74d55e": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleArchitectures": [ - { - "Ref": "CompatibleArchitecturesRef" - } - ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithSingleListRefArchitecturesIntrinsic" + "LayerName": { + "Fn::Sub": "layer-us-gov-west-1" + } }, "Type": "AWS::Lambda::LayerVersion" } } } - diff --git a/tests/translator/output/aws-us-gov/mixed_api_with_custom_domain_route53_multiple.json b/tests/translator/output/aws-us-gov/mixed_api_with_custom_domain_route53_multiple.json index 025997925c..d9a5bb35ac 100644 --- a/tests/translator/output/aws-us-gov/mixed_api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/aws-us-gov/mixed_api_with_custom_domain_route53_multiple.json @@ -1,193 +1,193 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", - "Resources": { - "MyRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", + "Resources": { + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "MyHttpApiApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV25fe29fe649" - }, - "Stage": { - "Ref": "MyHttpApiApiGatewayDefaultStage" - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "ApiGatewayDomainNameV25fe29fe649": { + "Properties": { + "DomainName": "admin.one.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyHttpApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyHttpApi" }, - "MyRestApiDeployment61887a4eed": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", - "RestApiId": { - "Ref": "MyRestApi" - }, - "StageName": "Stage" - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyHttpApiApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyHttpApi" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV25fe29fe649" }, - "ApiGatewayDomainNameV25fe29fe649": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.one.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } + "Stage": { + "Ref": "MyHttpApiApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "MyHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "MyHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyRestApiBasePathMapping": { + "Properties": { + "DomainName": { + "Ref": "ApiGatewayDomainName3fd2dbd8f8" }, - "MyRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyRestApiDeployment61887a4eed" - }, - "RestApiId": { - "Ref": "MyRestApi" - }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "RestApiId": { + "Ref": "MyRestApi" }, - "MyRestApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName3fd2dbd8f8" - }, - "RestApiId": { - "Ref": "MyRestApi" - }, - "Stage": { - "Ref": "MyRestApiProdStage" - } - } + "Stage": { + "Ref": "MyRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyRestApiDeployment61887a4eed": { + "Properties": { + "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "RestApiId": { + "Ref": "MyRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyRestApiDeployment61887a4eed" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "MyRestApi" }, - "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "abc123456", - "RecordSets": [ - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalDomainName" - ] - } - } - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "RecordSetGroup370194ff6e": { + "Properties": { + "HostedZoneId": "abc123456", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalDomainName" ] - } - } + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json index 07945dfb62..07c2e256b6 100644 --- a/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/aws-us-gov/no_implicit_api_with_serverless_rest_api_resource.json @@ -1,261 +1,261 @@ { "Resources": { "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "GetHtmlFunctionRole", + "GetHtmlFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" ] } } ] } - } - }, + }, + "Type": "AWS::S3::Bucket" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] - } - }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ThumbnailFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/resource_with_invalid_type.json b/tests/translator/output/aws-us-gov/resource_with_invalid_type.json index 793a992610..ed25f58b2a 100644 --- a/tests/translator/output/aws-us-gov/resource_with_invalid_type.json +++ b/tests/translator/output/aws-us-gov/resource_with_invalid_type.json @@ -1,17 +1,16 @@ { "Resources": { "FunctionInvalid": { - "Type": { - "AWS::Serverless::Function": "invalid_field" - }, "Properties": { "CodeUri": "s3://sam-demo-bucket/member_portal.zip", "Handler": "index.gethtml", "Runtime": "nodejs12.x" + }, + "Type": { + "AWS::Serverless::Function": "invalid_field" } }, "FunctionValid": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -31,13 +30,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "FunctionValidRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -50,7 +48,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -61,7 +60,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3.json b/tests/translator/output/aws-us-gov/s3.json index 31a839213c..2ccf01d45c 100644 --- a/tests/translator/output/aws-us-gov/s3.json +++ b/tests/translator/output/aws-us-gov/s3.json @@ -1,89 +1,91 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_create_remove.json b/tests/translator/output/aws-us-gov/s3_create_remove.json index ad5819408a..e2b13a0579 100644 --- a/tests/translator/output/aws-us-gov/s3_create_remove.json +++ b/tests/translator/output/aws-us-gov/s3_create_remove.json @@ -1,106 +1,110 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": "BucketNameParameter", "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" - }, + } + }, { + "Event": "s3:ObjectRemoved:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectRemoved:*" + } } ] - }, - "BucketName": "BucketNameParameter", - "BucketEncryption": { - "ServerSideEncryptionConfiguration": [{ - "ServerSideEncryptionByDefault": { - "SSEAlgorithm": "AES256" - } - }] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_existing_lambda_notification_configuration.json b/tests/translator/output/aws-us-gov/s3_existing_lambda_notification_configuration.json index 31a839213c..2ccf01d45c 100644 --- a/tests/translator/output/aws-us-gov/s3_existing_lambda_notification_configuration.json +++ b/tests/translator/output/aws-us-gov/s3_existing_lambda_notification_configuration.json @@ -1,89 +1,91 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json b/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json index 341682e520..d4d2030035 100644 --- a/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json +++ b/tests/translator/output/aws-us-gov/s3_existing_other_notification_configuration.json @@ -1,97 +1,97 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } - ], + ], "TopicConfigurations": [ { - "Topic": "my-super-awesome-topic", - "Event": "s3:ObjectRemoved:*" + "Event": "s3:ObjectRemoved:*", + "Topic": "my-super-awesome-topic" } ] } - }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_filter.json b/tests/translator/output/aws-us-gov/s3_filter.json index a90f71b88a..6d4845d33c 100644 --- a/tests/translator/output/aws-us-gov/s3_filter.json +++ b/tests/translator/output/aws-us-gov/s3_filter.json @@ -1,99 +1,101 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectCreated:*", "Filter": { "S3Key": { "Rules": [ { - "Name": "name", + "Name": "name", "Value": "value" } ] } - }, - "Event": "s3:ObjectCreated:*" + }, + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_intrinsics.json b/tests/translator/output/aws-us-gov/s3_intrinsics.json index 947ec4ef8b..606ed848bf 100644 --- a/tests/translator/output/aws-us-gov/s3_intrinsics.json +++ b/tests/translator/output/aws-us-gov/s3_intrinsics.json @@ -15,17 +15,14 @@ }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectCreated:*", "Filter": { "Fn::If": [ "MyCondition", @@ -51,20 +48,57 @@ } ] }, - "Event": "s3:ObjectCreated:*" + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } } ] } }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -77,54 +111,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/s3_multiple_events_same_bucket.json b/tests/translator/output/aws-us-gov/s3_multiple_events_same_bucket.json index d947979a10..159c977cd0 100644 --- a/tests/translator/output/aws-us-gov/s3_multiple_events_same_bucket.json +++ b/tests/translator/output/aws-us-gov/s3_multiple_events_same_bucket.json @@ -1,121 +1,124 @@ { "Resources": { - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ThumbnailFunctionImageBucketCreatesPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketDeletesPermission", "ThumbnailFunctionImageBucketCreatesPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketDeletesPermission", + "ThumbnailFunctionImageBucketCreatesPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectRemoved:*", "Filter": { "S3Key": { "Rules": [ { - "Name": "suffix", + "Name": "suffix", "Value": ".jpg" } ] } - }, - "Event": "s3:ObjectRemoved:*" - }, + }, + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } + }, { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionImageBucketDeletesPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, + }, + "Type": "AWS::S3::Bucket" + }, "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", + }, + "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ - "ThumbnailFunctionRole", + "ThumbnailFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketCreatesPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionImageBucketDeletesPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_multiple_functions.json b/tests/translator/output/aws-us-gov/s3_multiple_functions.json index fd4591fe1a..94e47aac6c 100644 --- a/tests/translator/output/aws-us-gov/s3_multiple_functions.json +++ b/tests/translator/output/aws-us-gov/s3_multiple_functions.json @@ -1,99 +1,44 @@ { "Resources": { - "FunctionOneRole": { - "Type": "AWS::IAM::Role", + "FunctionOne": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "FunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "FunctionTwoImageBucketPermission": { - "Type": "AWS::Lambda::Permission", + "FunctionOneImageBucketPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, "FunctionName": { - "Ref": "FunctionTwo" - }, - "Principal": "s3.amazonaws.com" - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "FunctionTwo", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - }, - { - "Function": { - "Fn::GetAtt": [ - "FunctionOne", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] + "Ref": "FunctionOne" }, - "PublicAccessBlockConfiguration": { - "BlockPublicAcls": true, - "BlockPublicPolicy": true, - "IgnorePublicAcls": true, - "RestrictPublicBuckets": true + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" } }, - "DependsOn": [ - "FunctionOneImageBucketPermission", - "FunctionTwoImageBucketPermission" - ] + "Type": "AWS::Lambda::Permission" }, - "FunctionTwoRole": { - "Type": "AWS::IAM::Role", + "FunctionOneRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -106,25 +51,22 @@ ] } } - ] - } - } - }, - "FunctionOneImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "FunctionOne" + ], + "Version": "2012-10-17" }, - "Principal": "s3.amazonaws.com" - } + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "FunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -140,34 +82,92 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionOne": { - "Type": "AWS::Lambda::Function", + "FunctionTwoImageBucketPermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "FunctionTwo" }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "FunctionOneRole", - "Arn" - ] + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionTwoRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "FunctionOneImageBucketPermission", + "FunctionTwoImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionTwo", + "Arn" + ] + } + }, + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionOne", + "Arn" + ] + } + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + } + }, + "Type": "AWS::S3::Bucket" } } } diff --git a/tests/translator/output/aws-us-gov/s3_with_condition.json b/tests/translator/output/aws-us-gov/s3_with_condition.json index 7ec67a04bb..131966c88a 100644 --- a/tests/translator/output/aws-us-gov/s3_with_condition.json +++ b/tests/translator/output/aws-us-gov/s3_with_condition.json @@ -2,120 +2,120 @@ "Conditions": { "MyCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { "Fn::If": [ - "MyCondition", + "MyCondition", { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" - }, + } + }, { "Ref": "AWS::NoValue" } ] } ] - }, + }, "Tags": [ { + "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission", "Value": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Ref": "ThumbnailFunctionImageBucketPermission" - }, + }, "no dependency" ] - }, - "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission" + } } ] - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Condition": "MyCondition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "MyCondition" - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - }, - "Condition": "MyCondition" - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "MyCondition" + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/s3_with_dependsOn.json b/tests/translator/output/aws-us-gov/s3_with_dependsOn.json index 5a5b0412b0..69b02cefb9 100644 --- a/tests/translator/output/aws-us-gov/s3_with_dependsOn.json +++ b/tests/translator/output/aws-us-gov/s3_with_dependsOn.json @@ -1,10 +1,6 @@ { "Resources": { - "Topic": { - "Type": "AWS::SNS::Topic" - }, "Images": { - "Type": "AWS::S3::Bucket", "DependsOn": [ "ThumbnailFunctionImageBucketPermission", "Topic" @@ -13,83 +9,87 @@ "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "Topic": { + "Type": "AWS::SNS::Topic" } } } diff --git a/tests/translator/output/aws-us-gov/self_managed_kafka_with_intrinsics.json b/tests/translator/output/aws-us-gov/self_managed_kafka_with_intrinsics.json index c031cfb096..6786ec20c2 100644 --- a/tests/translator/output/aws-us-gov/self_managed_kafka_with_intrinsics.json +++ b/tests/translator/output/aws-us-gov/self_managed_kafka_with_intrinsics.json @@ -1,38 +1,28 @@ { "Parameters": { "BatchSizeValue": { - "Type": "Number", - "Default": 100 + "Default": 100, + "Type": "Number" }, - "EnableValue": { - "Type": "String", - "Default": true + "ConsumerGroupValue": { + "Default": "consumergroup1", + "Type": "String" }, - "TopicsValue": { - "Type": "CommaDelimitedList", - "Default": "Topic" + "EnableValue": { + "Default": true, + "Type": "String" }, "KafkaBootstrapServersValue": { - "Type": "CommaDelimitedList", - "Default": "abc.xyz.com:9092,123.45.67.89:9096" + "Default": "abc.xyz.com:9092,123.45.67.89:9096", + "Type": "CommaDelimitedList" }, - "ConsumerGroupValue": { - "Type": "String", - "Default": "consumergroup1" + "TopicsValue": { + "Default": "Topic", + "Type": "CommaDelimitedList" } }, "Resources": { - "KafkaUserSecret": { - "Type": "AWS::SecretsManager::Secret", - "Properties": { - "Name": "KafkaUserPassword", - "SecretString": { - "Fn::Sub": "{\"username\":\"testBrokerUser\",\"password\":\"testBrokerPassword\"}" - } - } - }, "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -52,13 +42,57 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "BatchSize": { + "Ref": "BatchSizeValue" + }, + "Enabled": { + "Ref": "EnableValue" + }, + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": { + "Ref": "KafkaBootstrapServersValue" + } + } + }, + "SelfManagedKafkaEventSourceConfig": { + "ConsumerGroupId": { + "Ref": "ConsumerGroupValue" + } + }, + "SourceAccessConfigurations": [ + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + }, + { + "Type": "BASIC_AUTH", + "URI": { + "Ref": "KafkaUserSecret" + } + } + ], + "Topics": { + "Ref": "TopicsValue" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -71,7 +105,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -113,52 +148,17 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", + "KafkaUserSecret": { "Properties": { - "BatchSize": { - "Ref": "BatchSizeValue" - }, - "Enabled": { - "Ref": "EnableValue" - }, - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": { - "Ref": "TopicsValue" - }, - "SourceAccessConfigurations": [ - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - }, - { - "Type": "BASIC_AUTH", - "URI": { - "Ref": "KafkaUserSecret" - } - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": { - "Ref": "KafkaBootstrapServersValue" - } - } - }, - "SelfManagedKafkaEventSourceConfig": { - "ConsumerGroupId": { - "Ref": "ConsumerGroupValue" - } + "Name": "KafkaUserPassword", + "SecretString": { + "Fn::Sub": "{\"username\":\"testBrokerUser\",\"password\":\"testBrokerPassword\"}" } - } + }, + "Type": "AWS::SecretsManager::Secret" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json b/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json index e9a652d3b0..07b3755cbe 100644 --- a/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json +++ b/tests/translator/output/aws-us-gov/simple_table_ref_parameter_intrinsic.json @@ -1,5 +1,9 @@ { "Parameters": { + "EnableSSE": { + "Default": true, + "Type": "String" + }, "ReadCapacity": { "Default": 15, "Type": "Number" @@ -7,29 +11,11 @@ "WriteCapacity": { "Default": 15, "Type": "Number" - }, - "EnableSSE": { - "Default": true, - "Type": "String" } }, "Resources": { "MinimalTableRefParamLongForm": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "ProvisionedThroughput": { - "WriteCapacityUnits": { - "Ref": "WriteCapacity" - }, - "ReadCapacityUnits": { - "Ref": "ReadCapacity" - } - }, - "SSESpecification": { - "SSEEnabled": { - "Ref": "EnableSSE" - } - }, "AttributeDefinitions": [ { "AttributeName": "id", @@ -38,11 +24,25 @@ ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": { + "Ref": "ReadCapacity" + }, + "WriteCapacityUnits": { + "Ref": "WriteCapacity" + } + }, + "SSESpecification": { + "SSEEnabled": { + "Ref": "EnableSSE" } - ] - } + } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json b/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json index a02e088cd8..55ad2e3e58 100644 --- a/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json +++ b/tests/translator/output/aws-us-gov/simple_table_with_extra_tags.json @@ -7,42 +7,42 @@ }, "Resources": { "MinimalTableWithTags": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ], "Tags": [ { - "Value": "TagValue1", - "Key": "TagKey1" + "Key": "TagKey1", + "Value": "TagValue1" }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/simple_table_with_table_name.json b/tests/translator/output/aws-us-gov/simple_table_with_table_name.json index 57b9ef7a81..3778fe19f3 100644 --- a/tests/translator/output/aws-us-gov/simple_table_with_table_name.json +++ b/tests/translator/output/aws-us-gov/simple_table_with_table_name.json @@ -6,66 +6,66 @@ } }, "Resources": { - "MinimalTableWithTableName": { - "Type": "AWS::DynamoDB::Table", + "MinimalTableWithRefTableName": { "Properties": { - "TableName": "MySimpleTable", - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } - }, - "MinimalTableWithRefTableName": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "TableName": { "Ref": "MySimpleTableParameter" - }, - "BillingMode": "PAY_PER_REQUEST", + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTableWithSubTableName": { + "Properties": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } - }, - "MinimalTableWithSubTableName": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "TableName": { "Fn::Sub": "${AWS::StackName}MySimpleTable" - }, - "BillingMode": "PAY_PER_REQUEST", + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTableWithTableName": { + "Properties": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } + ], + "TableName": "MySimpleTable" + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/simpletable.json b/tests/translator/output/aws-us-gov/simpletable.json index c59f7a660d..7176a71daf 100644 --- a/tests/translator/output/aws-us-gov/simpletable.json +++ b/tests/translator/output/aws-us-gov/simpletable.json @@ -1,43 +1,43 @@ { "Resources": { - "MinimalTable": { - "Type": "AWS::DynamoDB::Table", + "CompleteTable": { "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { - "AttributeName": "id", - "AttributeType": "S" + "AttributeName": "member-number", + "AttributeType": "N" } - ], + ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "member-number", + "KeyType": "HASH" } - ] - } - }, - "CompleteTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "ProvisionedThroughput": { - "WriteCapacityUnits": 10, - "ReadCapacityUnits": 20 - }, + "ReadCapacityUnits": 20, + "WriteCapacityUnits": 10 + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTable": { + "Properties": { "AttributeDefinitions": [ { - "AttributeName": "member-number", - "AttributeType": "N" + "AttributeName": "id", + "AttributeType": "S" } - ], + ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "member-number" + "AttributeName": "id", + "KeyType": "HASH" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/simpletable_with_sse.json b/tests/translator/output/aws-us-gov/simpletable_with_sse.json index ab4c3d3f59..13df879afc 100644 --- a/tests/translator/output/aws-us-gov/simpletable_with_sse.json +++ b/tests/translator/output/aws-us-gov/simpletable_with_sse.json @@ -1,25 +1,25 @@ { - "Resources": { - "TableWithSSE": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "SSESpecification": { - "SSEEnabled": true - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] + "Resources": { + "TableWithSSE": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "SSESpecification": { + "SSEEnabled": true } - } + }, + "Type": "AWS::DynamoDB::Table" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/sns.json b/tests/translator/output/aws-us-gov/sns.json index 84508ffefe..37c84b7549 100644 --- a/tests/translator/output/aws-us-gov/sns.json +++ b/tests/translator/output/aws-us-gov/sns.json @@ -2,87 +2,87 @@ "Resources": { "Notifications": { "Type": "AWS::SNS::Topic" - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "Notifications" - } - } - }, + }, "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", + }, + "Handler": "index.save_notification", "Role": { "Fn::GetAtt": [ - "SaveNotificationFunctionRole", + "SaveNotificationFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "SaveNotificationFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/sns_existing_other_subscription.json b/tests/translator/output/aws-us-gov/sns_existing_other_subscription.json index 8eef98bebd..449dc02f51 100644 --- a/tests/translator/output/aws-us-gov/sns_existing_other_subscription.json +++ b/tests/translator/output/aws-us-gov/sns_existing_other_subscription.json @@ -1,96 +1,96 @@ { "Resources": { "Notifications": { - "Type": "AWS::SNS::Topic", "Properties": { "Subscription": [ { - "Endpoint": "my-queue-arn", + "Endpoint": "my-queue-arn", "Protocol": "sqs" } ] - } - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "Notifications" - } - } - }, + }, + "Type": "AWS::SNS::Topic" + }, "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", + }, + "Handler": "index.save_notification", "Role": { "Fn::GetAtt": [ - "SaveNotificationFunctionRole", + "SaveNotificationFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "SaveNotificationFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/sns_existing_sqs.json b/tests/translator/output/aws-us-gov/sns_existing_sqs.json index 94a1235762..4c47260f97 100644 --- a/tests/translator/output/aws-us-gov/sns_existing_sqs.json +++ b/tests/translator/output/aws-us-gov/sns_existing_sqs.json @@ -1,31 +1,11 @@ { "Resources": { - "Queue": { - "Type": "AWS::SQS::Queue" - }, - "Notifications": { - "Type": "AWS::SNS::Topic" - }, "NotificationA": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - { - "Ref": "Queue" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - }, - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -33,15 +13,63 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + } } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "Queue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "Notifications": { + "Type": "AWS::SNS::Topic" + }, + "Queue": { + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + }, "FilterPolicy": { "price_usd": [ { @@ -55,23 +83,32 @@ "example_corp" ] }, - "Endpoint": { + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 8, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "Queue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -84,7 +121,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -92,50 +130,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 8, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/sns_intrinsics.json b/tests/translator/output/aws-us-gov/sns_intrinsics.json index 0df391edf5..1deae39800 100644 --- a/tests/translator/output/aws-us-gov/sns_intrinsics.json +++ b/tests/translator/output/aws-us-gov/sns_intrinsics.json @@ -17,46 +17,37 @@ "Notifications": { "Type": "AWS::SNS::Topic" }, - "SaveNotificationFunctionNotificationTopicQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "SaveNotificationFunctionNotificationTopicQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "SaveNotificationFunction": { "Properties": { - "Queues": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Ref": "SaveNotificationFunctionNotificationTopicQueue" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + }, "FilterPolicy": { "Fn::If": [ "MyCondition", @@ -82,26 +73,72 @@ } ] }, + "Protocol": "sqs", "Region": { "Ref": "SnsRegion" }, - "Endpoint": { + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "SaveNotificationFunctionNotificationTopicQueue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SaveNotificationFunctionNotificationTopicQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunctionNotificationTopicQueuePolicy": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } + } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "SaveNotificationFunctionNotificationTopicQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -114,7 +151,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -122,50 +160,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/sns_outside_sqs.json b/tests/translator/output/aws-us-gov/sns_outside_sqs.json index 79c5ff389e..fa06c5c32e 100644 --- a/tests/translator/output/aws-us-gov/sns_outside_sqs.json +++ b/tests/translator/output/aws-us-gov/sns_outside_sqs.json @@ -1,18 +1,11 @@ { "Resources": { "NotificationB": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue" - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": "arn:aws:sqs:us-east-1:123456789012:MyQueue", - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -20,18 +13,48 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": "arn:aws:sqs:us-east-1:123456789012:MyQueue" } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Queues": [ + "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue" + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, "Notifications": { "Type": "AWS::SNS::Topic" }, + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": "arn:aws:sqs:us-east-1:123456789012:MyQueue", "FilterPolicy": { "price_usd": [ { @@ -45,18 +68,27 @@ "example_corp" ] }, - "Endpoint": "arn:aws:sqs:us-east-1:123456789012:MyQueue", "Protocol": "sqs", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 8, + "Enabled": true, + "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:MyQueue", + "FunctionName": { + "Ref": "SaveNotificationFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -69,7 +101,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -77,45 +110,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 8, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:MyQueue" - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/sns_sqs.json b/tests/translator/output/aws-us-gov/sns_sqs.json index d81d36c865..d8ada83369 100644 --- a/tests/translator/output/aws-us-gov/sns_sqs.json +++ b/tests/translator/output/aws-us-gov/sns_sqs.json @@ -3,46 +3,37 @@ "Notifications": { "Type": "AWS::SNS::Topic" }, - "SaveNotificationFunctionNotificationTopicQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "SaveNotificationFunctionNotificationTopicQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "SaveNotificationFunction": { "Properties": { - "Queues": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Ref": "SaveNotificationFunctionNotificationTopicQueue" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + }, "FilterPolicy": { "price_usd": [ { @@ -56,33 +47,69 @@ "example_corp" ] }, - "Endpoint": { + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "SaveNotificationFunctionNotificationTopicQueue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", + "SaveNotificationFunctionNotificationTopicQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunctionNotificationTopicQueuePolicy": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } + } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Queues": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "SaveNotificationFunctionNotificationTopicQueue" } - ], + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "SaveNotificationFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -95,48 +122,21 @@ ] } } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, - "EventSourceArn": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "FunctionName": { - "Ref": "SaveNotificationFunction" - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/sns_topic_outside_template.json b/tests/translator/output/aws-us-gov/sns_topic_outside_template.json index e91b956cfa..3f4fa2381e 100644 --- a/tests/translator/output/aws-us-gov/sns_topic_outside_template.json +++ b/tests/translator/output/aws-us-gov/sns_topic_outside_template.json @@ -3,88 +3,88 @@ "SNSTopicArn": { "Type": "String" } - }, + }, "Resources": { + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "SNSTopicArn" } - } - }, + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "SNSTopicArn" + } + }, + "Type": "AWS::Lambda::Permission" + }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "SNSTopicArn" - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/sqs.json b/tests/translator/output/aws-us-gov/sqs.json index 0d80717ab2..f01e85e43d 100644 --- a/tests/translator/output/aws-us-gov/sqs.json +++ b/tests/translator/output/aws-us-gov/sqs.json @@ -1,36 +1,6 @@ { "Resources": { - "SQSFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } - }, "SQSFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -44,14 +14,16 @@ ] }, "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "SQSFunctionMySqsQueue": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 10, "Enabled": false, @@ -59,7 +31,39 @@ "FunctionName": { "Ref": "SQSFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SQSFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_api_auth_default_scopes.json b/tests/translator/output/aws-us-gov/state_machine_with_api_auth_default_scopes.json index 6a466f04a9..aeb314cddf 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_api_auth_default_scopes.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_api_auth_default_scopes.json @@ -1,733 +1,733 @@ { - "Resources": { - "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/cognitowithauthnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoWithAuthNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "NONE": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoAuthorizerWithDefaultScopesRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoAuthorizerScopesOverwrittenRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesWithOverwrittenRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [ - "overwritten.read", - "overwritten.write" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:2" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } + "Resources": { + "MyApiWithCognitoAuth": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuthWithDefaultScopes": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:2" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyDefaultCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } } - }, - "MyStateMachineCognitoWithAuthNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoWithAuthNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/cognitoauthorizercopesoverwritten": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoAuthorizerScopesOverwrittenRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultScopesNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoAuthorizerWithDefaultScopesRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultScopesWithOverwrittenRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesWithOverwrittenRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [ + "overwritten.read", + "overwritten.write" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesWithOverwrittenRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoWithAuthNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment57b57dfc88" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeployment57b57dfc88": { + "Properties": { + "Description": "RestApi deployment id: 57b57dfc88b1b438a0437eadd869d77e938eedb6", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment57b57dfc88" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyStateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyStateMachineCognitoAuthorizerScopesOverwrittenRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiWithCognitoAuthDeployment57b57dfc88": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 57b57dfc88b1b438a0437eadd869d77e938eedb6" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoAuthorizerScopesOverwrittenRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoAuthorizerWithDefaultScopesRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoAuthorizerWithDefaultScopesRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyStateMachineCognitoAuthorizerWithDefaultScopesRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoAuthorizerWithDefaultScopesRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineCognitoAuthorizerScopesOverwrittenRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoAuthorizerScopesOverwrittenRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesWithOverwrittenRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "MyStateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesWithOverwrittenRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoWithAuthNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoWithAuthNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer.json b/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer.json index c7a7a8711d..a92a7a8387 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer.json @@ -1,384 +1,384 @@ { - "Resources": { - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startWithLambdaToken": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaTokenAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" + "StateMachineWithLambdaTokenAuthRole", + "Arn" ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaaffc688ce" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startNoAuth": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithNoAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "StateMachineWithLambdaTokenAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + }, + "securityDefinitions": { + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineWithLambdaTokenAuthRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment3c26186470": { + "Properties": { + "Description": "RestApi deployment id: 3c2618647036e31ff3ebf6ae8d4602ba63997fd7", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment3c26186470" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startNoAuth": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithNoAuthorizerRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ] - } - }, - "MyApiDeployment3c26186470": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 3c2618647036e31ff3ebf6ae8d4602ba63997fd7", - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment3c26186470" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } } - }, - "ServerlessRestApiDeploymentaaffc688ce": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aaffc688ce6d1b26ccd7a90641e103263f6240bb", - "StageName": "Stage" + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaaffc688ce": { + "Properties": { + "Description": "RestApi deployment id: aaffc688ce6d1b26ccd7a90641e103263f6240bb", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaaffc688ce" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - }, - "StateMachineWithNoAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaTokenAuthRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startWithLambdaToken": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaTokenAuthRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaTokenAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, - "x-amazon-apigateway-authtype": "custom" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaTokenAuthRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithNoAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer_maximum.json b/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer_maximum.json index 42ad354b45..56af1d5cfa 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer_maximum.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_api_authorizer_maximum.json @@ -1,690 +1,690 @@ { - "Resources": { - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "NONE": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithNoAuthorizerRole", + "Arn" ] - } - } - }, - "StateMachineWithLambdaRequestAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithLambdaRequestAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + } + }, + "/users": { + "delete": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" + "StateMachineWithLambdaRequestAuthorizerRole", + "Arn" ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + }, + "patch": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithLambdaTokenAuthorizerRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "MyApiDeployment2120b73f3e": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 2120b73f3e7efc28dc4baca314ee3b30d8d8c783", - "StageName": "Stage" - } - }, - "StateMachineWithDefaultAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithDefaultAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + }, + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthMultipleUserPools": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } + }, + "put": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithDefaultAuthorizerRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + }, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "Tags": [ + ] + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "__FunctionArn__": "arn:aws" } - ] - } - }, - "StateMachineWithLambdaTokenAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineWithLambdaTokenAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment2120b73f3e": { + "Properties": { + "Description": "RestApi deployment id: 2120b73f3e7efc28dc4baca314ee3b30d8d8c783", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment2120b73f3e" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment2120b73f3e" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithCognitoMultipleUserPoolsAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithDefaultAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithCognitoMultipleUserPoolsAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithDefaultAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaRequestAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "StateMachineWithNoAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaRequestAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaTokenAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithNoAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "NONE": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/users": { - "put": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithDefaultAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthMultipleUserPools": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "patch": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaTokenAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "delete": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaRequestAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaRequestAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, - "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, - "x-amazon-apigateway-authtype": "custom" - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaTokenAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithNoAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_api_resource_policy.json b/tests/translator/output/aws-us-gov/state_machine_with_api_resource_policy.json index f9b4100a56..42a3dc5da6 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_api_resource_policy.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_api_resource_policy.json @@ -1,482 +1,482 @@ { - "Resources": { - "MyStateMachineGetHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineGetHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/one": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineGetHtmlRole", + "Arn" ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineGetHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachinePutHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachinePostHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Allow", - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "NotIpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Allow", - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "NotIpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - } - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment17065a95ba" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "MyStateMachinePutHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachinePutHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/three": { + "put": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachinePutHtmlRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/two": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachinePostHtmlRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRole", - "Arn" + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "IpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } + ] + } ] + }, + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "IpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + } + ], + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment17065a95ba": { + "Properties": { + "Description": "RestApi deployment id: 17065a95bac1ac0e3dc22fef2ff7aa228539b1d2", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment17065a95ba" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyStateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyStateMachineGetHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "ExplicitApiDeployment17065a95ba": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 17065a95bac1ac0e3dc22fef2ff7aa228539b1d2", - "StageName": "Stage" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineGetHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachinePostHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "MyStateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachinePostHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachinePutHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyStateMachinePostHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachinePostHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachinePutHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_condition.json b/tests/translator/output/aws-us-gov/state_machine_with_condition.json index 7d67abe1a4..f723ffa179 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_condition.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_condition.json @@ -2,30 +2,30 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "test", + "test", "test" ] } - }, + }, "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "Condition": "TestCondition", "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachine", "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachine", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - }, - "Condition": "TestCondition" + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_condition_and_events.json b/tests/translator/output/aws-us-gov/state_machine_with_condition_and_events.json index 8e0a7a0ab3..c706371a84 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_condition_and_events.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_condition_and_events.json @@ -1,305 +1,305 @@ { - "Conditions": { - "TestCondition": { - "Fn::Equals": [ - "test", - "test" - ] - } - }, - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "test", + "test" + ] + } + }, + "Resources": { + "ServerlessRestApi": { + "Condition": "TestCondition", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "Fn::If": [ + "TestCondition", + { + "post": { + "Fn::If": [ + "TestCondition", + { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::If": [ + "TestCondition", + { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + }, + { + "Ref": "AWS::NoValue" + } + ] + } } + }, + { + "Ref": "AWS::NoValue" + } ] + } + }, + { + "Ref": "AWS::NoValue" } - }, - "Condition": "TestCondition" - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachine", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ] + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaeae651245": { + "Condition": "TestCondition", + "Properties": { + "Description": "RestApi deployment id: aeae651245fe7d417a17f2bea50b255f2727e2b8", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "TestCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaeae651245" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Condition": "TestCondition", + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineCWEvent": { + "Condition": "TestCondition", + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] + } + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineCWEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" ] - }, - "Condition": "TestCondition" - }, - "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaeae651245" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "TestCondition" - }, - "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } - ], - "Name": "TestSchedule" - }, - "Condition": "TestCondition" - }, - "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineMyApiEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] - }, - "Condition": "TestCondition" - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "Fn::If": [ - "TestCondition", - { - "post": { - "Fn::If": [ - "TestCondition", - { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::If": [ - "TestCondition", - { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - }, - "ServerlessRestApiDeploymentaeae651245": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aeae651245fe7d417a17f2bea50b255f2727e2b8", - "StageName": "Stage" - }, - "Condition": "TestCondition" - }, - "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineScheduleEvent": { + "Condition": "TestCondition", + "Properties": { + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" + ] + } + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineScheduleEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_cwe.json b/tests/translator/output/aws-us-gov/state_machine_with_cwe.json index 95940a3534..fb1f076239 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_cwe.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_cwe.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,76 +24,61 @@ "terminated" ] } - }, + }, "State": "ENABLED", "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_object.json b/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_object.json index d324146d61..53c1e6a325 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_object.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_object.json @@ -1,138 +1,138 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "states.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithDefinitionInS3", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithDefinitionInS3", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_string.json b/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_string.json index 4caed80743..6d02e1940d 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_string.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_definition_S3_string.json @@ -1,137 +1,137 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "states.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithDefinitionInS3", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithDefinitionInS3", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "Key": "stateMachine:createdBy", + "Value": "SAM" } - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_definition_substitutions.json b/tests/translator/output/aws-us-gov/state_machine_with_definition_substitutions.json index 3695a061e6..873ea3d071 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_definition_substitutions.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_definition_substitutions.json @@ -1,13 +1,12 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", @@ -17,65 +16,16 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -88,38 +38,23 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "my_state_var_1": "Pass", - "my_state_var_2": "Task" - }, - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, "DefinitionString": { "Fn::Join": [ "\n", @@ -143,13 +78,78 @@ ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "my_state_var_1": "Pass", + "my_state_var_2": "Task" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq.json b/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq.json index e49e64256f..24a206c3d4 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,78 +24,63 @@ "terminated" ] } - }, + }, "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "DeadLetterConfig": { + "Arn": "TestDlqArn" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "DeadLetterConfig": { - "Arn": "TestDlqArn" - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq_generated.json b/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq_generated.json index 7e57f89263..70f2a5724d 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq_generated.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_eb_dlq_generated.json @@ -1,11 +1,22 @@ { "Resources": { - "TestDLQ": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -13,121 +24,110 @@ "terminated" ] } - }, + }, "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, + "Arn": { + "Ref": "StateMachine" + }, "DeadLetterConfig": { "Arn": { "Fn::GetAtt": [ - "TestDLQ", + "TestDLQ", "Arn" ] } - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - { - "Ref": "TestDLQ" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "TestDLQ", - "Arn" - ] - }, - "Effect": "Allow", + "Action": "sqs:SendMessage", "Condition": { "ArnEquals": { "aws:SourceArn": { "Fn::GetAtt": [ - "StateMachineCWEvent", + "StateMachineCWEvent", "Arn" ] } } - }, + }, + "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "TestDLQ", + "Arn" + ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Queues": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Ref": "TestDLQ" } ] - } - }, + }, + "Type": "AWS::SQS::QueuePolicy" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TestDLQ": { + "Properties": {}, + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_eb_retry_policy.json b/tests/translator/output/aws-us-gov/state_machine_with_eb_retry_policy.json index bff94e177a..18813d71f7 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_eb_retry_policy.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_eb_retry_policy.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,79 +24,64 @@ "terminated" ] } - }, + }, "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", "Arn": { "Ref": "StateMachine" - }, + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 300, + "MaximumEventAgeInSeconds": 300, "MaximumRetryAttempts": 5 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_event_schedule_state.json b/tests/translator/output/aws-us-gov/state_machine_with_event_schedule_state.json index a38e480ed1..c3b472071f 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_event_schedule_state.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_event_schedule_state.json @@ -1,7 +1,6 @@ { "Resources": { "ScheduledStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -14,10 +13,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "ScheduledStateMachineSchedule1": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -37,13 +36,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule1Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,11 +54,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule1RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -71,13 +69,14 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule1RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ScheduledStateMachineSchedule2": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -99,13 +98,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule2Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -118,11 +116,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule2RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -133,13 +131,14 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule2RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ScheduledStateMachineSchedule3": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -161,13 +160,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule3Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,11 +178,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule3RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -195,10 +193,12 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule3RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/aws-us-gov/state_machine_with_explicit_api.json b/tests/translator/output/aws-us-gov/state_machine_with_explicit_api.json index 70ef4676a3..4e1e8c9b24 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_explicit_api.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_explicit_api.json @@ -1,210 +1,210 @@ { - "Resources": { - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ] + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment05bc9f394c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment05bc9f394c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - } - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_express_logging.json b/tests/translator/output/aws-us-gov/state_machine_with_express_logging.json index 338d3a0e73..31470da6af 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_express_logging.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_express_logging.json @@ -1,180 +1,180 @@ { "Resources": { + "ExpressLogGroup": { + "Type": "AWS::Logs::LogGroup" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "ExpressLogGroup", + "Arn" + ] + } + } + } + ], + "IncludeExecutionData": false, + "Level": "FATAL" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStandardStateMachineWithLogging", + "StateMachineType": "EXPRESS", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] - }, - "Effect": "Allow" + } } - ] - } - }, + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + }, { - "PolicyName": "StateMachineRolePolicy1", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", "logs:DescribeLogGroups" - ], + ], + "Effect": "Allow", "Resource": [ "*" - ], - "Effect": "Allow" + ] } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy1" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "ExpressLogGroup": { - "Type": "AWS::Logs::LogGroup" - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStandardStateMachineWithLogging", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "LoggingConfiguration": { - "IncludeExecutionData": false, - "Level": "FATAL", - "Destinations": [ - { - "CloudWatchLogsLogGroup": { - "LogGroupArn": { - "Fn::GetAtt": [ - "ExpressLogGroup", - "Arn" - ] - } - } - } - ] - }, - "StateMachineType": "EXPRESS", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_implicit_api.json b/tests/translator/output/aws-us-gov/state_machine_with_implicit_api.json index ebb4b1c02c..0b098f32b9 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_implicit_api.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_implicit_api.json @@ -1,210 +1,210 @@ { - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment05bc9f394c" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + "StateMachineMyApiEventRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment05bc9f394c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_implicit_api_globals.json b/tests/translator/output/aws-us-gov/state_machine_with_implicit_api_globals.json index c28b4704f7..eaf74275c3 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_implicit_api_globals.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_implicit_api_globals.json @@ -1,232 +1,232 @@ { - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + "StateMachineMyApiEventRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment1f01b589d4" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment1f01b589d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 1f01b589d4e226c84a3e14ca738b5d060e7b611a", - "StageName": "Stage" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "Tags": [ + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "12345" + ] + }, + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/startMyExecution", { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "__Stage__": "Prod" } + ] + } + ] + }, + "Version": "2012-10-17" + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment1f01b589d4": { + "Properties": { + "Description": "RestApi deployment id: 1f01b589d4e226c84a3e14ca738b5d060e7b611a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment1f01b589d4" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/startMyExecution", - { - "__Stage__": "Prod" - } - ] - } - ], - "Effect": "Deny", - "Principal": { - "AWS": [ - "12345" - ] - } - } - } - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_inline_definition.json b/tests/translator/output/aws-us-gov/state_machine_with_inline_definition.json index 722bc9ec70..5564d443ee 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_inline_definition.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_inline_definition.json @@ -1,89 +1,89 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyBasicStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Deny" + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyBasicStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_inline_definition_intrinsics.json b/tests/translator/output/aws-us-gov/state_machine_with_inline_definition_intrinsics.json index b3d2b21543..016333d09f 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_inline_definition_intrinsics.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_inline_definition_intrinsics.json @@ -1,82 +1,32 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "MyFunctionRole", "Arn" ] }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,21 +39,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ @@ -128,12 +79,14 @@ ] ] }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, "RoleArn": { "Fn::GetAtt": [ "StateMachineRole", @@ -141,16 +94,63 @@ ] }, "StateMachineName": "MyBasicStateMachine", - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StateMachineType": "STANDARD" - } + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_inline_policies.json b/tests/translator/output/aws-us-gov/state_machine_with_inline_policies.json index b3d2b21543..016333d09f 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_inline_policies.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_inline_policies.json @@ -1,82 +1,32 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "MyFunctionRole", "Arn" ] }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,21 +39,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ @@ -128,12 +79,14 @@ ] ] }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, "RoleArn": { "Fn::GetAtt": [ "StateMachineRole", @@ -141,16 +94,63 @@ ] }, "StateMachineName": "MyBasicStateMachine", - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StateMachineType": "STANDARD" - } + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_managed_policy.json b/tests/translator/output/aws-us-gov/state_machine_with_managed_policy.json index 496ec9f64a..1c3d6837e5 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_managed_policy.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_managed_policy.json @@ -1,57 +1,57 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithManagedPolicy", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/AmazonDynamoDBFullAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithManagedPolicy", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_null_events.json b/tests/translator/output/aws-us-gov/state_machine_with_null_events.json index eb62a90415..772ee4032d 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_null_events.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_null_events.json @@ -1,7 +1,6 @@ { "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -14,7 +13,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_permissions_boundary.json b/tests/translator/output/aws-us-gov/state_machine_with_permissions_boundary.json index 550c0ae536..2c4fef8c17 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_permissions_boundary.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_permissions_boundary.json @@ -1,114 +1,167 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Policies": [ + }, + "Runtime": "python2.7", + "Tags": [ { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "apigateway.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment05bc9f394c" - }, + }, "RestApiId": { "Ref": "ServerlessRestApi" - }, + }, "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -116,265 +169,212 @@ "terminated" ] } - }, + }, "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineCWEventRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "events.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" } ] - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineMyApiEventRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" } } - } - } - }, - "swagger": "2.0" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - }, - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - } - } - }, + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { "functionName": { "Ref": "MyFunction" } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "StateMachineRolePolicy0" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineScheduleEvent": { "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Policies": [ + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" ] } } - ], + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineScheduleEventRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } - ], - "Name": "TestSchedule" - } - }, - "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Policies": [ { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { - "Action": "states:StartExecution", + "Action": "states:StartExecution", + "Effect": "Allow", "Resource": { "Ref": "StateMachine" - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_role.json b/tests/translator/output/aws-us-gov/state_machine_with_role.json index 0db8c03ab0..7b3b87fb4b 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_role.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_role.json @@ -1,22 +1,22 @@ { "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachineWithRole", "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "my-state-machine.asl.json" - }, - "StateMachineType": "STANDARD", + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithRole", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_sam_policy_templates.json b/tests/translator/output/aws-us-gov/state_machine_with_sam_policy_templates.json index cc8fd1b194..e3e9297b12 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_sam_policy_templates.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_sam_policy_templates.json @@ -1,40 +1,7 @@ { "Resources": { - "ResolverLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "resolver.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "resolver.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ResolverLambdaRole", - "Arn" - ] - }, - "Runtime": "python3.8", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, "NestedWorkflow": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "StarterLambda", - "Arn" - ] - } - }, - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", "DefinitionString": { "Fn::Join": [ "\n", @@ -60,67 +27,49 @@ ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "StarterLambda", + "Arn" + ] + } + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, - "StarterLambda": { - "Type": "AWS::Lambda::Function", + "OutputStore": { "Properties": { - "Handler": "starter.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "starter.zip" - }, - "Role": { - "Fn::GetAtt": [ - "StarterLambdaRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ + "AttributeDefinitions": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "AttributeName": "id", + "AttributeType": "S" } - ] - } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "TableName": "MySimpleTable" + }, + "Type": "AWS::DynamoDB::Table" + }, + "ProcessingQueue": { + "Type": "AWS::SQS::Queue" }, "ProcessingWorkflow": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_4": { - "Ref": "NestedWorkflow" - }, - "definition_substitution_5": { - "Ref": "OutputStore" - }, - "definition_substitution_2": { - "Ref": "ResolverLambda" - }, - "definition_substitution_3": { - "Ref": "ProcessingQueue" - }, - "definition_substitution_1": { - "Fn::GetAtt": [ - "StarterLambda", - "Arn" - ] - } - }, - "RoleArn": { - "Fn::GetAtt": [ - "ProcessingWorkflowRole", - "Arn" - ] - }, "DefinitionString": { "Fn::Join": [ "\n", @@ -231,50 +180,45 @@ ] ] }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "StarterLambda", + "Arn" + ] + }, + "definition_substitution_2": { + "Ref": "ResolverLambda" + }, + "definition_substitution_3": { + "Ref": "ProcessingQueue" + }, + "definition_substitution_4": { + "Ref": "NestedWorkflow" + }, + "definition_substitution_5": { + "Ref": "OutputStore" } - ] - } - }, - "StarterLambdaRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + }, + "RoleArn": { + "Fn::GetAtt": [ + "ProcessingWorkflowRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "ProcessingWorkflowRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -287,18 +231,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "ProcessingWorkflowRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -308,20 +253,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy0" }, { - "PolicyName": "ProcessingWorkflowRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -334,20 +279,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy1" }, { - "PolicyName": "ProcessingWorkflowRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -357,20 +302,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy2" }, { - "PolicyName": "ProcessingWorkflowRolePolicy3", "PolicyDocument": { "Statement": [ { "Action": [ "states:StartExecution" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", @@ -383,14 +328,13 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy3" }, { - "PolicyName": "ProcessingWorkflowRolePolicy4", "PolicyDocument": { "Statement": [ { @@ -399,6 +343,7 @@ "dynamodb:UpdateItem", "dynamodb:BatchWriteItem" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -420,48 +365,101 @@ } ] } - ], - "Effect": "Allow" + ] } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy4" } ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "OutputStore": { - "Type": "AWS::DynamoDB::Table", + "ResolverLambda": { "Properties": { - "KeySchema": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "resolver.zip" + }, + "Handler": "resolver.handler", + "Role": { + "Fn::GetAtt": [ + "ResolverLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.8", + "Tags": [ { - "KeyType": "HASH", - "AttributeName": "id" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ResolverLambdaRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "TableName": "MySimpleTable", - "AttributeDefinitions": [ + "Tags": [ { - "AttributeName": "id", - "AttributeType": "S" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "BillingMode": "PAY_PER_REQUEST" - } + ] + }, + "Type": "AWS::IAM::Role" }, - "ProcessingQueue": { - "Type": "AWS::SQS::Queue" + "StarterLambda": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "starter.zip" + }, + "Handler": "starter.handler", + "Role": { + "Fn::GetAtt": [ + "StarterLambdaRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ResolverLambdaRole": { - "Type": "AWS::IAM::Role", + "StarterLambdaRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -474,18 +472,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_schedule.json b/tests/translator/output/aws-us-gov/state_machine_with_schedule.json index 8730521be8..434e16586c 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_schedule.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_schedule.json @@ -1,80 +1,80 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", "Properties": { - "State": "DISABLED", - "ScheduleExpression": "rate(1 minute)", - "Name": "TestSchedule", - "Description": "test schedule", + "Description": "test schedule", + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "State": "DISABLED", "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineScheduleEventRole", + "StateMachineScheduleEventRole", "Arn" ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Policies": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_schedule_dlq_retry_policy.json b/tests/translator/output/aws-us-gov/state_machine_with_schedule_dlq_retry_policy.json index 5d49175a96..95164ba8a7 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_schedule_dlq_retry_policy.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_schedule_dlq_retry_policy.json @@ -1,87 +1,87 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", "Properties": { - "State": "DISABLED", - "ScheduleExpression": "rate(1 minute)", - "Name": "TestSchedule", - "Description": "test schedule", + "Description": "test schedule", + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "State": "DISABLED", "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "DeadLetterConfig": { - "Arn": "Arn" - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", "Arn": { "Ref": "StateMachine" - }, + }, + "DeadLetterConfig": { + "Arn": "Arn" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 300, + "MaximumEventAgeInSeconds": 300, "MaximumRetryAttempts": 5 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" + ] } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Policies": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_standard_logging.json b/tests/translator/output/aws-us-gov/state_machine_with_standard_logging.json index f351648c4d..e100b2ad75 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_standard_logging.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_standard_logging.json @@ -1,180 +1,180 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "StandardLogGroup": { - "Type": "AWS::Logs::LogGroup" - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - }, - { - "PolicyName": "StateMachineRolePolicy1", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", - "logs:DescribeLogGroups" - ], - "Resource": [ - "*" - ], - "Effect": "Allow" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "StandardLogGroup": { + "Type": "AWS::Logs::LogGroup" + }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStandardStateMachineWithLogging", + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, "DefinitionSubstitutions": { "my_lambda_arn": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] } - }, + }, "LoggingConfiguration": { - "IncludeExecutionData": true, - "Level": "ALL", "Destinations": [ { "CloudWatchLogsLogGroup": { "LogGroupArn": { "Fn::GetAtt": [ - "StandardLogGroup", + "StandardLogGroup", "Arn" ] } } } + ], + "IncludeExecutionData": true, + "Level": "ALL" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + }, + "StateMachineName": "MyStandardStateMachineWithLogging", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy1" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_tags.json b/tests/translator/output/aws-us-gov/state_machine_with_tags.json index 6016da4201..615b6ced5b 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_tags.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_tags.json @@ -1,105 +1,105 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithTags", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + }, + { + "Key": "TagTwo", + "Value": "ValueTwo" + }, + { + "Key": "TagOne", + "Value": "ValueOne" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Deny" + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - }, - { - "Value": "ValueTwo", - "Key": "TagTwo" - }, - { - "Value": "ValueOne", - "Key": "TagOne" + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithTags", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" - }, + "Key": "stateMachine:createdBy", + "Value": "SAM" + }, { - "Value": "ValueTwo", - "Key": "TagTwo" - }, + "Key": "TagTwo", + "Value": "ValueTwo" + }, { - "Value": "ValueOne", - "Key": "TagOne" + "Key": "TagOne", + "Value": "ValueOne" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_xray_policies.json b/tests/translator/output/aws-us-gov/state_machine_with_xray_policies.json index 287d1b6265..a197b462e4 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_xray_policies.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_xray_policies.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -77,13 +76,12 @@ "TracingConfiguration": { "Enabled": true } - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -96,20 +94,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/AWSXRayDaemonWriteAccess" ], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ "MyFunction", @@ -117,8 +114,10 @@ ] } } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } ], "Tags": [ @@ -127,7 +126,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/state_machine_with_xray_role.json b/tests/translator/output/aws-us-gov/state_machine_with_xray_role.json index 156d59d448..7efdf80eed 100644 --- a/tests/translator/output/aws-us-gov/state_machine_with_xray_role.json +++ b/tests/translator/output/aws-us-gov/state_machine_with_xray_role.json @@ -1,25 +1,25 @@ { - "Resources": { - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachineWithXRayTracing", - "TracingConfiguration": { - "Enabled": true - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithXRayTracing", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ], + "TracingConfiguration": { + "Enabled": true } + }, + "Type": "AWS::StepFunctions::StateMachine" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/aws-us-gov/streams.json b/tests/translator/output/aws-us-gov/streams.json index b871156743..ea0daf0d81 100644 --- a/tests/translator/output/aws-us-gov/streams.json +++ b/tests/translator/output/aws-us-gov/streams.json @@ -1,7 +1,6 @@ { "Resources": { "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -15,56 +14,16 @@ ] }, "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "KinesisFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Handler": "stream.kinesis_handler", - "Role": { - "Fn::GetAtt": [ - "KinesisFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "MSKFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Handler": "stream.msk_handler", - "Role": { - "Fn::GetAtt": [ - "MSKFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 200, "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", @@ -72,39 +31,64 @@ "Ref": "DynamoDBFunction" }, "StartingPosition": "LATEST" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "KinesisFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" + }, + "Handler": "stream.kinesis_handler", + "Role": { + "Fn::GetAtt": [ + "KinesisFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "KinesisFunctionMyKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 100, "Enabled": false, @@ -113,76 +97,106 @@ "Ref": "KinesisFunction" }, "StartingPosition": "TRIM_HORIZON" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KinesisFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MSKFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" + }, + "Handler": "stream.msk_handler", + "Role": { + "Fn::GetAtt": [ + "MSKFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MSKFunctionMyMSKStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", "FunctionName": { "Ref": "MSKFunction" }, "StartingPosition": "LATEST", - "Topics": ["Topic1"] - } + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MSKFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/unsupported_resources.json b/tests/translator/output/aws-us-gov/unsupported_resources.json index b358015d05..5d0f51c19b 100644 --- a/tests/translator/output/aws-us-gov/unsupported_resources.json +++ b/tests/translator/output/aws-us-gov/unsupported_resources.json @@ -1,17 +1,17 @@ { "Resources": { - "UnknownTypeShouldBeAccepted": { - "Type": "AWS::Other::ABCD", + "ResourceMissingTypeShouldBeAccepted": { "Properties": { - "StageName": "Prod", - "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json" + "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json", + "StageName": "Prod" } }, - "ResourceMissingTypeShouldBeAccepted": { + "UnknownTypeShouldBeAccepted": { "Properties": { - "StageName": "Prod", - "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json" - } + "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json", + "StageName": "Prod" + }, + "Type": "AWS::Other::ABCD" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/aws-us-gov/version_deletion_policy_precedence.json b/tests/translator/output/aws-us-gov/version_deletion_policy_precedence.json index 0beb66af0e..05e1afbd9d 100644 --- a/tests/translator/output/aws-us-gov/version_deletion_policy_precedence.json +++ b/tests/translator/output/aws-us-gov/version_deletion_policy_precedence.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,38 +20,53 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "MinimalFunction2": { + "DeletionPolicy": "Delete", "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunction2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "MinimalFunction2Aliaslive": { + "DeletionPolicy": "Delete", "Properties": { - "Name": "live", "FunctionName": { - "Ref": "MinimalFunction" + "Ref": "MinimalFunction2" }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "MinimalFunction2Version640128d35d", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction2Role": { + "DeletionPolicy": "Delete", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +79,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,64 +91,37 @@ "Value": "SAM" } ] - } - }, - "MinimalFunction2": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Delete", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunction2Role", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::IAM::Role" }, "MinimalFunction2Version640128d35d": { - "Type": "AWS::Lambda::Version", "DeletionPolicy": "Delete", "Properties": { "Description": "sam-testing", "FunctionName": { "Ref": "MinimalFunction2" } - } + }, + "Type": "AWS::Lambda::Version" }, - "MinimalFunction2Aliaslive": { - "Type": "AWS::Lambda::Alias", - "DeletionPolicy": "Delete", + "MinimalFunctionAliaslive": { "Properties": { - "Name": "live", "FunctionName": { - "Ref": "MinimalFunction2" + "Ref": "MinimalFunction" }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunction2Version640128d35d", + "MinimalFunctionVersion640128d35d", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "MinimalFunction2Role": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Delete", + "MinimalFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -146,7 +134,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -157,7 +146,18 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/basic_application.json b/tests/translator/output/basic_application.json index 058e8037e5..96a827f8e5 100644 --- a/tests/translator/output/basic_application.json +++ b/tests/translator/output/basic_application.json @@ -2,99 +2,99 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Resources": { - "NormalApplication": { - "Type": "AWS::CloudFormation::Stack", + "ApplicationWithCondition": { + "Condition": "TestCondition", "Properties": { - "NotificationARNs": [ - "arn:aws:sns:us-east-1:123456789012:sns-arn" - ], - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", - "TimeoutInMinutes": 15, - "Parameters": { - "IdentityNameParameter": "IdentityName" - }, "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" - }, + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "TagValue", - "Key": "TagName" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, - "BasicApplication": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "ApplicationWithLocationUrl": { "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "TagName2", + "Value": "TagValue2" } - ] - } - }, - "ApplicationWithLocationUrl": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "BasicApplication": { "Properties": { - "TemplateURL": "https://s3-us-east-1.amazonaws.com/demo-bucket/template.yaml", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "TagValue2", - "Key": "TagName2" + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" } - ] - } - }, - "ApplicationWithCondition": { - "Type": "AWS::CloudFormation::Stack", + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url" + }, + "Type": "AWS::CloudFormation::Stack" + }, + "NormalApplication": { "Properties": { - "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "NotificationARNs": [ + "arn:aws:sns:us-east-1:123456789012:sns-arn" + ], + "Parameters": { + "IdentityNameParameter": "IdentityName" + }, "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "serverlessrepo:applicationId", + "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world" + }, { - "Value": "arn:aws:serverlessrepo:us-east-1:123456789012:applications/hello-world", - "Key": "serverlessrepo:applicationId" - }, + "Key": "serverlessrepo:semanticVersion", + "Value": "1.0.2" + }, { - "Value": "1.0.2", - "Key": "serverlessrepo:semanticVersion" + "Key": "TagName", + "Value": "TagValue" } - ] - }, - "Condition": "TestCondition" + ], + "TemplateURL": "https://awsserverlessrepo-changesets-xxx.s3.amazonaws.com/signed-url", + "TimeoutInMinutes": 15 + }, + "Type": "AWS::CloudFormation::Stack" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/basic_function.json b/tests/translator/output/basic_function.json index 8b1e210f44..7d25e094c4 100644 --- a/tests/translator/output/basic_function.json +++ b/tests/translator/output/basic_function.json @@ -1,459 +1,459 @@ { "Parameters": { - "SomeParameter": { - "Default": "param", - "Type": "String" - }, "SomeOtherParameter": { - "Default": "otherparam", + "Default": "otherparam", + "Type": "String" + }, + "SomeParameter": { + "Default": "param", "Type": "String" } - }, + }, "Resources": { - "FunctionWithInlineCode": { - "Type": "AWS::Lambda::Function", + "CompleteFunction": { "Properties": { - "TracingConfig": { - "Mode": "Active" - }, "Code": { - "ZipFile": "hello world" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Starter Lambda Function", + "Environment": { + "Variables": { + "Name": "Value", + "Name2": "Value2" + } + }, + "FunctionName": "MyAwesomeFunction", + "Handler": "hello.handler", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", + ], + "Timeout": 60, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", + { + "Ref": "SomeParameter" + }, + { + "Ref": "SomeOtherParameter" + } + ] + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithCodeUriObject": { + "Properties": { + "Code": { + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "1" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithInlineCodeRole", + "FunctionWithCodeUriObjectRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithCodeUriObjectRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithInlineCode": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + "ZipFile": "hello world" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "FunctionWithInlineCodeRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "TracingConfig": { + "Mode": "Active" + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithInlineCodeRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithPolicies": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", + "FunctionWithPoliciesRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithPoliciesRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithPolicyDocument": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "FunctionWithPolicyDocumentRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithCodeUriObjectRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithPolicyDocumentRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Path": "/", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Policies": [ { - "PolicyName": "root", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Allow" + "Action": [ + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "ec2.amazonaws.com" - ] - } - } - ] - } - } - }, - "CompleteFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Starter Lambda Function", - "VpcConfig": { - "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08", - { - "Ref": "SomeParameter" - }, - { - "Ref": "SomeOtherParameter" - } - ], - "SecurityGroupIds": [ - "sg-edcd9784" - ] - }, + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Environment": { - "Variables": { - "Name2": "Value2", - "Name": "Value" + "Key": "lambda:createdBy", + "Value": "SAM" } - }, - "Handler": "hello.handler", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "Runtime": "python2.7", - "FunctionName": "MyAwesomeFunction" - } - }, - "FunctionWithCodeUriObject": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithRoleRef": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": "1" - }, + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithCodeUriObjectRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithTracing": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionWithTracingRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "TracingConfig": { + "Mode": "Active" + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithTracingRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithInlineCodeRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithTracingRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "ec2.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "FunctionWithTracing": { - "Type": "AWS::Lambda::Function", - "Properties": { - "TracingConfig": { - "Mode": "Active" - }, - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithTracingRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + ], + "Version": "2012-10-17" + }, + "Path": "/", "Policies": [ { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", "PolicyDocument": { "Statement": [ { - "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" + "Action": "*", + "Effect": "Allow", + "Resource": "*" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "root" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/basic_function_with_tags.json b/tests/translator/output/basic_function_with_tags.json index 1a23e3ae30..ccae8b0698 100644 --- a/tests/translator/output/basic_function_with_tags.json +++ b/tests/translator/output/basic_function_with_tags.json @@ -1,5 +1,5 @@ { - "AWSTemplateFormatVersion": "2010-09-09", + "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { "TagValueParam": { "Default": "Val", @@ -7,107 +7,107 @@ } }, "Resources": { - "AlexaSkillFuncRole": { - "Type": "AWS::IAM::Role", + "AlexaSkillFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "AlexaSkillFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" }, { - "Value": "TagValue1", - "Key": "TagKey1" + "Key": "TagKey1", + "Value": "TagValue1" }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "AlexaSkillFuncAlexaSkillEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "AlexaSkillFunc" + }, + "Principal": "alexa-appkit.amazon.com" + }, + "Type": "AWS::Lambda::Permission" + }, + "AlexaSkillFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "AlexaSkillFuncAlexaSkillEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "AlexaSkillFunc" - }, - "Principal": "alexa-appkit.amazon.com" - } - }, - "AlexaSkillFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Value": "TagValue1", - "Key": "TagKey1" - }, + "Key": "TagKey1", + "Value": "TagValue1" + }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "AlexaSkillFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/basic_function_withimageuri.json b/tests/translator/output/basic_function_withimageuri.json index 2dfe458983..8ea57e5e6b 100644 --- a/tests/translator/output/basic_function_withimageuri.json +++ b/tests/translator/output/basic_function_withimageuri.json @@ -1,54 +1,61 @@ { "Parameters": { - "SomeParameter": { - "Type": "String", - "Default": "param" - }, "SomeOtherParameter": { - "Type": "String", - "Default": "otherparam" + "Default": "otherparam", + "Type": "String" + }, + "SomeParameter": { + "Default": "param", + "Type": "String" } }, "Resources": { - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "CompleteImageFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Principal": { - "Service": [ - "ec2.amazonaws.com" - ] - }, - "Action": [ - "sts:AssumeRole" - ] - } - ] + "Code": { + "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, - "Path": "/", - "Policies": [ + "Description": "Starter Lambda Function", + "Environment": { + "Variables": { + "Name": "Value", + "Name2": "Value2" + } + }, + "FunctionName": "MyAwesomeFunction", + "ImageConfig": { + "Command": "/bin/sh", + "EntryPoint": "echo hello world!", + "WorkingDirectory": "/var/task" + }, + "PackageType": "Image", + "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", + "Tags": [ { - "PolicyName": "root", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": "*", - "Resource": "*" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ] - } + ], + "Timeout": 60, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "subnet-9d4a7b6c", + "subnet-65ea5f08", + { + "Ref": "SomeParameter" + }, + { + "Ref": "SomeOtherParameter" + } + ] + } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithPolicies": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" @@ -56,7 +63,7 @@ "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "MinimalImageFunctionRole", + "FunctionWithPoliciesRole", "Arn" ] }, @@ -66,13 +73,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunctionRole": { - "Type": "AWS::IAM::Role", + "FunctionWithPoliciesRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -85,10 +91,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" ], "Tags": [ { @@ -96,10 +104,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalImageFunctionPackageTypeAndImageConfig": { - "Type": "AWS::Lambda::Function", + "FunctionWithPolicyDocument": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" @@ -107,7 +115,7 @@ "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "MinimalImageFunctionPackageTypeAndImageConfigRole", + "FunctionWithPolicyDocumentRole", "Arn" ] }, @@ -116,19 +124,13 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "ImageConfig": { - "WorkingDirectory": "/var/task", - "Command": "/bin/sh", - "EntryPoint": "echo hello world!" - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MinimalImageFunctionPackageTypeAndImageConfigRole": { - "Type": "AWS::IAM::Role", + "FunctionWithPolicyDocumentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -141,74 +143,93 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ] + }, + "PolicyName": "FunctionWithPolicyDocumentRolePolicy0" + } + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "CompleteImageFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithRoleRef": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, "PackageType": "Image", - "Description": "Starter Lambda Function", - "FunctionName": "MyAwesomeFunction", - "Role": "arn:aws:iam::012345678901:role/lambda_basic_execution", - "Timeout": 60, - "VpcConfig": { - "SecurityGroupIds": [ - "sg-edcd9784" - ], - "SubnetIds": [ - "subnet-9d4a7b6c", - "subnet-65ea5f08", - { - "Ref": "SomeParameter" - }, - { - "Ref": "SomeOtherParameter" - } + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" ] }, - "Environment": { - "Variables": { - "Name": "Value", - "Name2": "Value2" + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalImageFunction": { + "Properties": { + "Code": { + "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" + }, + "PackageType": "Image", + "Role": { + "Fn::GetAtt": [ + "MinimalImageFunctionRole", + "Arn" + ] }, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "ImageConfig": { - "WorkingDirectory": "/var/task", - "Command": "/bin/sh", - "EntryPoint": "echo hello world!" - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithPolicies": { - "Type": "AWS::Lambda::Function", + "MinimalImageFunctionPackageTypeAndImageConfig": { "Properties": { "Code": { "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" }, + "ImageConfig": { + "Command": "/bin/sh", + "EntryPoint": "echo hello world!", + "WorkingDirectory": "/var/task" + }, "PackageType": "Image", "Role": { "Fn::GetAtt": [ - "FunctionWithPoliciesRole", + "MinimalImageFunctionPackageTypeAndImageConfigRole", "Arn" ] }, @@ -218,13 +239,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithPoliciesRole": { - "Type": "AWS::IAM::Role", + "MinimalImageFunctionPackageTypeAndImageConfigRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -237,11 +257,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { @@ -249,34 +269,42 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "FunctionWithPolicyDocument": { - "Type": "AWS::Lambda::Function", + "MinimalImageFunctionRole": { "Properties": { - "Code": { - "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" - }, - "PackageType": "Image", - "Role": { - "Fn::GetAtt": [ - "FunctionWithPolicyDocumentRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "FunctionWithPolicyDocumentRole": { - "Type": "AWS::IAM::Role", + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -285,59 +313,31 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "ec2.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Path": "/", "Policies": [ { - "PolicyName": "FunctionWithPolicyDocumentRolePolicy0", "PolicyDocument": { "Statement": [ { - "Action": [ - "dynamodb:*" - ], + "Action": "*", "Effect": "Allow", "Resource": "*" } - ] - } - } - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "FunctionWithRoleRef": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ImageUri": "123456789.dkr.ecr.region.amazonaws.suffix/myimage:latest" - }, - "PackageType": "Image", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" + ], + "Version": "2012-10-17" + }, + "PolicyName": "root" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/basic_layer.json b/tests/translator/output/basic_layer.json index 44c1be560d..94901714e4 100644 --- a/tests/translator/output/basic_layer.json +++ b/tests/translator/output/basic_layer.json @@ -2,7 +2,7 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "beta", + "beta", "beta" ] } @@ -14,94 +14,94 @@ } }, "Resources": { - "LayerWithCondition7c655e10ea": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + "CompleteLayer5d71a60e81": { + "DeletionPolicy": "Retain", "Properties": { + "CompatibleRuntimes": [ + "python3.6", + "python2.7" + ], "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "LayerWithCondition" - }, - "Condition": "TestCondition" - }, - "MinimalLayer0c7f96cce7": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "Description": "Starter Lambda Layer", + "LayerName": "MyAwesomeLayer", + "LicenseInfo": "License information" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithArchitecturesab56a78493": { + "DeletionPolicy": "Retain", "Properties": { + "CompatibleArchitectures": [ + "x86_64", + "arm64" + ], "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MinimalLayer" - } - }, - "CompleteLayer5d71a60e81": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "LayerName": "LayerWithArchitectures" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithCaseInsensitiveRetentionPolicyead52a491d": { + "DeletionPolicy": "Delete", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "LayerName": "MyAwesomeLayer", - "Description": "Starter Lambda Layer", - "LicenseInfo": "License information", - "CompatibleRuntimes": [ - "python3.6", - "python2.7" - ] - } - }, - "LayerWithContentUriObjectbdbf1b82ac": { - "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", + }, + "LayerName": "LayerWithCaseInsensitiveRetentionPolicy" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "LayerWithCondition7c655e10ea": { + "Condition": "TestCondition", + "DeletionPolicy": "Retain", "Properties": { "Content": { - "S3Bucket": "somebucket", - "S3Key": "somekey", - "S3ObjectVersion": "v1" - }, - "LayerName": "LayerWithContentUriObject" - } + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "LayerWithCondition" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithCaseInsensitiveRetentionPolicyead52a491d": { + "LayerWithContentUriObjectbdbf1b82ac": { "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" + "S3Bucket": "somebucket", + "S3Key": "somekey", + "S3ObjectVersion": "v1" }, - "LayerName": "LayerWithCaseInsensitiveRetentionPolicy" - } + "LayerName": "LayerWithContentUriObject" + }, + "Type": "AWS::Lambda::LayerVersion" }, "LayerWithRetentionPolicyParamcc64815342": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, "LayerName": "LayerWithRetentionPolicyParam" - } - }, - "LayerWithArchitecturesab56a78493": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "MinimalLayer0c7f96cce7": { + "DeletionPolicy": "Retain", "Properties": { "Content": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" - }, - "CompatibleArchitectures": [ - "x86_64", - "arm64" - ], - "LayerName": "LayerWithArchitectures" - } + }, + "LayerName": "MinimalLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } } diff --git a/tests/translator/output/cloudwatch_logs_with_ref.json b/tests/translator/output/cloudwatch_logs_with_ref.json index 9c0faab670..cc400918da 100644 --- a/tests/translator/output/cloudwatch_logs_with_ref.json +++ b/tests/translator/output/cloudwatch_logs_with_ref.json @@ -1,5 +1,6 @@ { "AWSTemplateFormatVersion": "2010-09-09", + "Description": "Example CloudWatch Logs + Lambda", "Parameters": { "FilterPattern": { "Default": "My filter pattern", @@ -11,28 +12,7 @@ } }, "Resources": { - "TriggeredFunctionCWLogEvent": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Fn::GetAtt": [ - "TriggeredFunction", - "Arn" - ] - }, - "FilterPattern": { - "Ref": "FilterPattern" - }, - "LogGroupName": { - "Ref": "LogGroupName" - } - }, - "DependsOn": [ - "TriggeredFunctionCWLogEventPermission" - ] - }, "TriggeredFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -49,50 +29,40 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", + "TriggeredFunctionCWLogEvent": { + "DependsOn": [ + "TriggeredFunctionCWLogEventPermission" + ], "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "DestinationArn": { + "Fn::GetAtt": [ + "TriggeredFunction", + "Arn" ] + }, + "FilterPattern": { + "Ref": "FilterPattern" + }, + "LogGroupName": { + "Ref": "LogGroupName" } - } + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "TriggeredFunctionCWLogEventPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "TriggeredFunction" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -103,8 +73,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "Example CloudWatch Logs + Lambda" + } } diff --git a/tests/translator/output/cloudwatchevent.json b/tests/translator/output/cloudwatchevent.json index 8d7f5d0d4e..cc8dfdc259 100644 --- a/tests/translator/output/cloudwatchevent.json +++ b/tests/translator/output/cloudwatchevent.json @@ -1,185 +1,185 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/cloudwatchevent_intrinsics.json b/tests/translator/output/cloudwatchevent_intrinsics.json index 1a12bb7851..a1fc524b63 100644 --- a/tests/translator/output/cloudwatchevent_intrinsics.json +++ b/tests/translator/output/cloudwatchevent_intrinsics.json @@ -1,14 +1,4 @@ { - "Parameters": { - "PathA": { - "Type": "String", - "Default": "SomeInputPath" - }, - "PathB": { - "Type": "String", - "Default": "AnotherInputPath" - } - }, "Conditions": { "PathCondition": { "Fn::Equals": [ @@ -17,9 +7,18 @@ ] } }, + "Parameters": { + "PathA": { + "Default": "SomeInputPath", + "Type": "String" + }, + "PathB": { + "Default": "AnotherInputPath", + "Type": "String" + } + }, "Resources": { "LambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -39,40 +38,10 @@ "Value": "SAM" } ] - } - }, - "LambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "LambdaFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { "EventBusName": { "Fn::Join": [ @@ -125,10 +94,10 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "LambdaFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -141,7 +110,38 @@ "Arn" ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "LambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/cloudwatchlog.json b/tests/translator/output/cloudwatchlog.json index 52af6f5963..92e79041a4 100644 --- a/tests/translator/output/cloudwatchlog.json +++ b/tests/translator/output/cloudwatchlog.json @@ -1,23 +1,6 @@ { "Resources": { - "TriggeredFunctionCWLogEvent": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Fn::GetAtt": [ - "TriggeredFunction", - "Arn" - ] - }, - "FilterPattern": "My filter pattern", - "LogGroupName": "MyCWLogGroup" - }, - "DependsOn": [ - "TriggeredFunctionCWLogEventPermission" - ] - }, "TriggeredFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -34,50 +17,36 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", + "TriggeredFunctionCWLogEvent": { + "DependsOn": [ + "TriggeredFunctionCWLogEventPermission" + ], "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "DestinationArn": { + "Fn::GetAtt": [ + "TriggeredFunction", + "Arn" ] - } - } + }, + "FilterPattern": "My filter pattern", + "LogGroupName": "MyCWLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "TriggeredFunctionCWLogEventPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "TriggeredFunction" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -86,7 +55,38 @@ } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/cognito_userpool_with_event.json b/tests/translator/output/cognito_userpool_with_event.json index f9b14e1617..073e957f7d 100644 --- a/tests/translator/output/cognito_userpool_with_event.json +++ b/tests/translator/output/cognito_userpool_with_event.json @@ -1,53 +1,6 @@ { "Resources": { - "UserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "LambdaConfig": { - "PreSignUp": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - }, - "PostConfirmation": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - }, - "VerifyAuthChallengeResponse": { - "Fn::GetAtt": [ - "ImplicitApiFunction", - "Arn" - ] - } - }, - "Policies": { - "PasswordPolicy": { - "MinimumLength": 8 - } - }, - "Schema": [ - { - "AttributeDataType": "String", - "Name": "email", - "Required": false - } - ], - "UserAttributeUpdateSettings": { - "AttributesRequireVerificationBeforeUpdate": [ - "email" - ] - }, - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName" - } - }, "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -67,13 +20,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "ImplicitApiFunctionCognitoPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ImplicitApiFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "UserPool", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -86,7 +54,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -97,23 +66,54 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "ImplicitApiFunctionCognitoPermission": { - "Type": "AWS::Lambda::Permission", + "UserPool": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ImplicitApiFunction" + "LambdaConfig": { + "PostConfirmation": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + }, + "PreSignUp": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + }, + "VerifyAuthChallengeResponse": { + "Fn::GetAtt": [ + "ImplicitApiFunction", + "Arn" + ] + } }, - "Principal": "cognito-idp.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "UserPool", - "Arn" + "Policies": { + "PasswordPolicy": { + "MinimumLength": 8 + } + }, + "Schema": [ + { + "AttributeDataType": "String", + "Name": "email", + "Required": false + } + ], + "UserAttributeUpdateSettings": { + "AttributesRequireVerificationBeforeUpdate": [ + "email" ] - } - } + }, + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" + ] + }, + "Type": "AWS::Cognito::UserPool" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/congito_userpool_with_sms_configuration.json b/tests/translator/output/congito_userpool_with_sms_configuration.json index 3ec561c399..0a3c432fa9 100644 --- a/tests/translator/output/congito_userpool_with_sms_configuration.json +++ b/tests/translator/output/congito_userpool_with_sms_configuration.json @@ -1,32 +1,6 @@ { "Resources": { - "MyCognitoUserPool": { - "Type": "AWS::Cognito::UserPool", - "Properties": { - "LambdaConfig": { - "PreSignUp": { - "Fn::GetAtt": [ - "HelloWorldFunction", - "Arn" - ] - } - }, - "SmsConfiguration": { - "SnsCallerArn": { - "Fn::GetAtt": [ - "UserPoolRole", - "Arn" - ] - }, - "ExternalId": { - "Ref": "ExternalId" - } - }, - "UserPoolName": "PreSignup" - } - }, "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -46,13 +20,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionCognitoPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyCognitoUserPool", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +54,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,23 +66,33 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "HelloWorldFunctionCognitoPermission": { - "Type": "AWS::Lambda::Permission", + "MyCognitoUserPool": { "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "HelloWorldFunction" + "LambdaConfig": { + "PreSignUp": { + "Fn::GetAtt": [ + "HelloWorldFunction", + "Arn" + ] + } }, - "Principal": "cognito-idp.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "MyCognitoUserPool", - "Arn" - ] - } - } + "SmsConfiguration": { + "ExternalId": { + "Ref": "ExternalId" + }, + "SnsCallerArn": { + "Fn::GetAtt": [ + "UserPoolRole", + "Arn" + ] + } + }, + "UserPoolName": "PreSignup" + }, + "Type": "AWS::Cognito::UserPool" } } } diff --git a/tests/translator/output/connector_api_to_function.json b/tests/translator/output/connector_api_to_function.json index 0c8e4f20aa..48c626930d 100644 --- a/tests/translator/output/connector_api_to_function.json +++ b/tests/translator/output/connector_api_to_function.json @@ -15,7 +15,10 @@ "Type": "MOCK" }, "ResourceId": { - "Fn::GetAtt": ["MyApiGateway", "RootResourceId"] + "Fn::GetAtt": [ + "MyApiGateway", + "RootResourceId" + ] }, "RestApiId": { "Ref": "MyApiGateway" @@ -46,17 +49,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyServerlessFunction", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyApiGatewayV2" - }, - "SourceQualifier": "*" + } } ] } @@ -79,17 +85,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyServerlessFunction", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyApiGateway" - }, - "SourceQualifier": "*" + } } ] } @@ -112,17 +121,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyServerlessApi" - }, - "SourceQualifier": "*" + } } ] } @@ -145,17 +157,20 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { + "SourceQualifier": "*", "SourceResourceId": { "Ref": "MyHttpApi" - }, - "SourceQualifier": "*" + } } ] } @@ -169,7 +184,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -274,7 +292,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -291,10 +312,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/connector_bucket_to_function.json b/tests/translator/output/connector_bucket_to_function.json index 46cbd623ec..0c4f2124df 100644 --- a/tests/translator/output/connector_bucket_to_function.json +++ b/tests/translator/output/connector_bucket_to_function.json @@ -1,7 +1,9 @@ { "Resources": { "Bucket": { - "DependsOn": ["MyConnectorWriteLambdaPermission"], + "DependsOn": [ + "MyConnectorWriteLambdaPermission" + ], "Properties": { "BucketName": "random-bucket-name", "NotificationConfiguration": { @@ -9,7 +11,10 @@ { "Event": "s3:ObjectCreated:*", "Function": { - "Fn::GetAtt": ["InvokedFunction", "Arn"] + "Fn::GetAtt": [ + "InvokedFunction", + "Arn" + ] } } ] @@ -24,7 +29,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["FunctionRole", "Arn"] + "Fn::GetAtt": [ + "FunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -41,10 +49,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -78,7 +90,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["Function", "Arn"] + "Fn::GetAtt": [ + "Function", + "Arn" + ] }, "Principal": "s3.amazonaws.com", "SourceAccount": { diff --git a/tests/translator/output/connector_esm_dependson.json b/tests/translator/output/connector_esm_dependson.json index b63e9a587d..f5be6465e5 100644 --- a/tests/translator/output/connector_esm_dependson.json +++ b/tests/translator/output/connector_esm_dependson.json @@ -1,255 +1,313 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Role": { - "Ref": "SomeRole" - } - } - }, - "MyQueue1": { - "Type": "AWS::SQS::Queue" - }, - "MyQueue2": { - "Type": "AWS::SQS::Queue" - }, - "MyQueue3": { - "Type": "AWS::SQS::Queue" - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table" - }, - "MyEventSourceMapping1": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue1", "Arn"] - } - }, - "DependsOn": ["MyConnector1Policy"] - }, - "MyEventSourceMapping2": { - "DependsOn": ["SomeDep", "MyConnector2Policy"], - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue2", "Arn"] - } - } - }, - "MyEventSourceMapping3": { - "DependsOn": ["SomeOtherDep", "MyConnector3Policy"], - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyQueue3", "Arn"] - } - } - }, - "MyEventSourceMapping4": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] - } - }, - "DependsOn": ["MyConnector4Policy"] - }, "MyConnector1Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector1": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector2Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector2": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector3Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector3": { - "Source": { - "Type": "AWS::SQS::Queue" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::SQS::Queue" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", - "Action": ["sqs:DeleteMessage"], "Resource": [ { - "Fn::GetAtt": ["MyQueue3", "Arn"] + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] } ] }, { + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], "Resource": [ { - "Fn::GetAtt": ["MyQueue3", "Arn"] + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyConnector4Policy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "MyConnector4": { - "Source": { - "Type": "AWS::DynamoDB::Table" - }, "Destination": { "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::DynamoDB::Table" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "dynamodb:DescribeStream", "dynamodb:GetRecords", "dynamodb:GetShardIterator", "dynamodb:ListStreams" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] } ] } - ] + ], + "Version": "2012-10-17" }, "Roles": [ { "Ref": "SomeRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyEventSourceMapping1": { + "DependsOn": [ + "MyConnector1Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping2": { + "DependsOn": [ + "SomeDep", + "MyConnector2Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping3": { + "DependsOn": [ + "SomeOtherDep", + "MyConnector3Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyQueue3", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyEventSourceMapping4": { + "DependsOn": [ + "MyConnector4Policy" + ], + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + }, + "FunctionName": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunction": { + "Properties": { + "Role": { + "Ref": "SomeRole" + } + }, + "Type": "AWS::Lambda::Function" + }, + "MyQueue1": { + "Type": "AWS::SQS::Queue" + }, + "MyQueue2": { + "Type": "AWS::SQS::Queue" + }, + "MyQueue3": { + "Type": "AWS::SQS::Queue" + }, + "MyTable": { + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/connector_function_to_s3.json b/tests/translator/output/connector_function_to_s3.json index e9eb664469..6c49fa4daa 100644 --- a/tests/translator/output/connector_function_to_s3.json +++ b/tests/translator/output/connector_function_to_s3.json @@ -38,14 +38,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/*", { "DestinationArn": { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] } } ] @@ -65,14 +71,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/*", { "DestinationArn": { - "Fn::GetAtt": ["MyBucket", "Arn"] + "Fn::GetAtt": [ + "MyBucket", + "Arn" + ] } } ] @@ -97,7 +109,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -114,10 +129,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/connector_function_to_sqs.json b/tests/translator/output/connector_function_to_sqs.json index bbc9cba968..911f7a6a2d 100644 --- a/tests/translator/output/connector_function_to_sqs.json +++ b/tests/translator/output/connector_function_to_sqs.json @@ -17,11 +17,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -62,7 +68,10 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -94,11 +103,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:ReceiveMessage", "sqs:GetQueueAttributes"], + "Action": [ + "sqs:ReceiveMessage", + "sqs:GetQueueAttributes" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] }, @@ -112,7 +127,10 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } @@ -141,7 +159,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -176,7 +197,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -193,10 +217,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/connector_function_to_table.json b/tests/translator/output/connector_function_to_table.json index 9bddc49790..0dbe304d79 100644 --- a/tests/translator/output/connector_function_to_table.json +++ b/tests/translator/output/connector_function_to_table.json @@ -28,14 +28,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -81,14 +87,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -108,14 +120,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -161,14 +179,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -214,14 +238,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -253,7 +283,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, @@ -292,7 +325,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyServerlessFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyServerlessFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -309,10 +345,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/connector_hardcoded_lambda_arn.json b/tests/translator/output/connector_hardcoded_lambda_arn.json index 1684af6d04..3da2074e63 100644 --- a/tests/translator/output/connector_hardcoded_lambda_arn.json +++ b/tests/translator/output/connector_hardcoded_lambda_arn.json @@ -19,7 +19,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["SomeLambda", "Arn"] + "Fn::GetAtt": [ + "SomeLambda", + "Arn" + ] }, "Principal": "sns.amazonaws.com", "SourceArn": { diff --git a/tests/translator/output/connector_hardcoded_props.json b/tests/translator/output/connector_hardcoded_props.json index 6571e85f5c..35916275e8 100644 --- a/tests/translator/output/connector_hardcoded_props.json +++ b/tests/translator/output/connector_hardcoded_props.json @@ -1,234 +1,201 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function" - }, - "MyRule": { - "Type": "AWS::Events::Rule" - }, - "MyQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyTopic": { - "Type": "AWS::SNS::Topic" - }, - "MyApiV1": { - "Type": "AWS::ApiGateway::RestApi" - }, - "MyApiV2": { - "Type": "AWS::ApiGatewayV2::Api" - }, - "MySfn": { - "Type": "AWS::StepFunctions::StateMachine" - }, - "RuleToTopicTopicPolicy": { - "Type": "AWS::SNS::TopicPolicy", + "ApiV1ToLambdaWriteLambdaPermission": { "Metadata": { "aws:sam:connectors": { - "RuleToTopic": { - "Source": { - "Type": "AWS::Events::Rule" - }, + "ApiV1ToLambda": { "Destination": { - "Type": "AWS::SNS::Topic" + "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::ApiGateway::RestApi" } } } }, "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { - "Effect": "Allow", - "Principal": { - "Service": "events.amazonaws.com" - }, - "Resource": { - "Fn::GetAtt": ["Egg", "Baz"] - }, - "Action": "sns:Publish", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Fn::GetAtt": ["MyRule", "Arn"] - } - } + "SourceQualifier": "Prod/GET/foobar", + "SourceResourceId": { + "Ref": "MyApiV1" } } ] - }, - "Topics": [ - { - "Fn::GetAtt": ["Egg", "Baz"] - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, - "TopicToQueueQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "ApiV2ToLambdaWriteLambdaPermission": { "Metadata": { "aws:sam:connectors": { - "TopicToQueue": { - "Source": { - "Type": "AWS::SNS::Topic" - }, + "ApiV2ToLambda": { "Destination": { - "Type": "AWS::SQS::Queue" + "Type": "AWS::Lambda::Function" + }, + "Source": { + "Type": "AWS::ApiGatewayV2::Api" } } } }, "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", { - "Effect": "Allow", - "Principal": { - "Service": "sns.amazonaws.com" - }, - "Resource": { - "Ref": "MyQueue" - }, - "Action": "sqs:SendMessage", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "MyTopic" - } - } + "SourceQualifier": "*", + "SourceResourceId": { + "Ref": "MyApiV2" } } ] - }, - "Queues": [ - { - "Fn::If": [ - true, - { - "Ref": "Foo" - }, - { - "Ref": "Bar" - } - ] - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, "LambdaToQueuePolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "LambdaToQueue": { - "Source": { - "Type": "AWS::Lambda::Function" - }, "Destination": { "Type": "AWS::SQS::Queue" + }, + "Source": { + "Type": "AWS::Lambda::Function" } } } }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": [ "sqs:DeleteMessage", "sqs:SendMessage", "sqs:ChangeMessageVisibility", "sqs:PurgeQueue" ], + "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } - ] + ], + "Version": "2012-10-17" }, - "Roles": ["MyCoolRole"] - } + "Roles": [ + "MyCoolRole" + ] + }, + "Type": "AWS::IAM::ManagedPolicy" }, - "ApiV1ToLambdaWriteLambdaPermission": { - "Type": "AWS::Lambda::Permission", + "MyApiV1": { + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiV2": { + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyFunction": { + "Type": "AWS::Lambda::Function" + }, + "MyQueue": { + "Type": "AWS::SQS::Queue" + }, + "MyRule": { + "Type": "AWS::Events::Rule" + }, + "MySfn": { + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyTopic": { + "Type": "AWS::SNS::Topic" + }, + "RuleToTopicTopicPolicy": { "Metadata": { "aws:sam:connectors": { - "ApiV1ToLambda": { - "Source": { - "Type": "AWS::ApiGateway::RestApi" - }, + "RuleToTopic": { "Destination": { - "Type": "AWS::Lambda::Function" + "Type": "AWS::SNS::Topic" + }, + "Source": { + "Type": "AWS::Events::Rule" } } } }, "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", + "PolicyDocument": { + "Statement": [ { - "SourceResourceId": { - "Ref": "MyApiV1" + "Action": "sns:Publish", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Fn::GetAtt": [ + "MyRule", + "Arn" + ] + } + } }, - "SourceQualifier": "Prod/GET/foobar" - } - ] - } - } - }, - "ApiV2ToLambdaWriteLambdaPermission": { - "Type": "AWS::Lambda::Permission", - "Metadata": { - "aws:sam:connectors": { - "ApiV2ToLambda": { - "Source": { - "Type": "AWS::ApiGatewayV2::Api" - }, - "Destination": { - "Type": "AWS::Lambda::Function" + "Effect": "Allow", + "Principal": { + "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "Egg", + "Baz" + ] + } } + ], + "Version": "2012-10-17" + }, + "Topics": [ + { + "Fn::GetAtt": [ + "Egg", + "Baz" + ] } - } + ] }, - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${SourceResourceId}/${SourceQualifier}", - { - "SourceResourceId": { - "Ref": "MyApiV2" - }, - "SourceQualifier": "*" - } - ] - } - } + "Type": "AWS::SNS::TopicPolicy" }, "SfnToSfnPolicy": { - "Type": "AWS::IAM::ManagedPolicy", "Metadata": { "aws:sam:connectors": { "SfnToSfn": { - "Source": { + "Destination": { "Type": "AWS::StepFunctions::StateMachine" }, - "Destination": { + "Source": { "Type": "AWS::StepFunctions::StateMachine" } } @@ -236,18 +203,22 @@ }, "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { + "Action": [ + "states:DescribeExecution" + ], "Effect": "Allow", - "Action": ["states:DescribeExecution"], "Resource": [ { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", { "DestinationName": { - "Fn::GetAtt": ["MySfn", "Name"] + "Fn::GetAtt": [ + "MySfn", + "Name" + ] } } ] @@ -255,8 +226,10 @@ ] }, { + "Action": [ + "events:DescribeRule" + ], "Effect": "Allow", - "Action": ["events:DescribeRule"], "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" @@ -264,20 +237,29 @@ ] }, { + "Action": [ + "states:StartExecution" + ], "Effect": "Allow", - "Action": ["states:StartExecution"], - "Resource": ["some-other-arn"] + "Resource": [ + "some-other-arn" + ] }, { + "Action": [ + "states:StopExecution" + ], "Effect": "Allow", - "Action": ["states:StopExecution"], "Resource": [ { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", { "DestinationName": { - "Fn::GetAtt": ["MySfn", "Name"] + "Fn::GetAtt": [ + "MySfn", + "Name" + ] } } ] @@ -285,18 +267,77 @@ ] }, { + "Action": [ + "events:PutTargets", + "events:PutRule" + ], "Effect": "Allow", - "Action": ["events:PutTargets", "events:PutRule"], "Resource": [ { "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" } ] } - ] + ], + "Version": "2012-10-17" + }, + "Roles": [ + "MyRoleNice" + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "TopicToQueueQueuePolicy": { + "Metadata": { + "aws:sam:connectors": { + "TopicToQueue": { + "Destination": { + "Type": "AWS::SQS::Queue" + }, + "Source": { + "Type": "AWS::SNS::Topic" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "MyTopic" + } + } + }, + "Effect": "Allow", + "Principal": { + "Service": "sns.amazonaws.com" + }, + "Resource": { + "Ref": "MyQueue" + } + } + ], + "Version": "2012-10-17" }, - "Roles": ["MyRoleNice"] - } + "Queues": [ + { + "Fn::If": [ + true, + { + "Ref": "Foo" + }, + { + "Ref": "Bar" + } + ] + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" } } } diff --git a/tests/translator/output/connector_hardcoded_rolename.json b/tests/translator/output/connector_hardcoded_rolename.json index f16ea349e4..00c8aefe87 100644 --- a/tests/translator/output/connector_hardcoded_rolename.json +++ b/tests/translator/output/connector_hardcoded_rolename.json @@ -26,14 +26,19 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyQueue", "Arn"] + "Fn::GetAtt": [ + "MyQueue", + "Arn" + ] } ] } ], "Version": "2012-10-17" }, - "Roles": ["MyCoolRole"] + "Roles": [ + "MyCoolRole" + ] }, "Type": "AWS::IAM::ManagedPolicy" }, @@ -44,7 +49,10 @@ }, "Handler": "foo", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "python3.9", "Tags": [ @@ -61,10 +69,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], diff --git a/tests/translator/output/connector_rule_to_eventbus.json b/tests/translator/output/connector_rule_to_eventbus.json index e4c3f79d6b..462ea044dd 100644 --- a/tests/translator/output/connector_rule_to_eventbus.json +++ b/tests/translator/output/connector_rule_to_eventbus.json @@ -25,11 +25,16 @@ "PolicyDocument": { "Statement": [ { - "Action": ["events:PutEvents"], + "Action": [ + "events:PutEvents" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["EventBus", "Arn"] + "Fn::GetAtt": [ + "EventBus", + "Arn" + ] } ] } @@ -61,7 +66,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["events:PutEvents"], + "Action": [ + "events:PutEvents" + ], "Effect": "Allow", "Resource": [ { @@ -83,18 +90,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["EventBus", "Arn"] + "Fn::GetAtt": [ + "EventBus", + "Arn" + ] }, "Id": "EventBus", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] @@ -104,7 +119,9 @@ "MyNewEventsRuleToDefaultBus": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", @@ -115,7 +132,10 @@ }, "Id": "EventBus", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] diff --git a/tests/translator/output/connector_rule_to_sfn.json b/tests/translator/output/connector_rule_to_sfn.json index f5b90955d8..f5703dba97 100644 --- a/tests/translator/output/connector_rule_to_sfn.json +++ b/tests/translator/output/connector_rule_to_sfn.json @@ -17,7 +17,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["states:StartExecution"], + "Action": [ + "states:StartExecution" + ], "Effect": "Allow", "Resource": [ { @@ -39,18 +41,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["StateMachine", "Arn"] + "Fn::GetAtt": [ + "StateMachine", + "Arn" + ] }, "Id": "StateMachine", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] @@ -96,11 +106,17 @@ }, "DefinitionSubstitutions": { "definition_substitution_1": { - "Fn::GetAtt": ["StateMachineFunction", "Arn"] + "Fn::GetAtt": [ + "StateMachineFunction", + "Arn" + ] } }, "RoleArn": { - "Fn::GetAtt": ["StateMachineRole", "Arn"] + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] }, "StateMachineType": "EXPRESS", "Tags": [ @@ -117,10 +133,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["states.amazonaws.com"] + "Service": [ + "states.amazonaws.com" + ] } } ], @@ -132,7 +152,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ diff --git a/tests/translator/output/connector_rule_to_sns.json b/tests/translator/output/connector_rule_to_sns.json index 78fd335694..cffbb77f04 100644 --- a/tests/translator/output/connector_rule_to_sns.json +++ b/tests/translator/output/connector_rule_to_sns.json @@ -21,7 +21,10 @@ "Condition": { "ArnEquals": { "aws:SourceArn": { - "Fn::GetAtt": ["MyNewEventsRule", "Arn"] + "Fn::GetAtt": [ + "MyNewEventsRule", + "Arn" + ] } } }, @@ -47,18 +50,26 @@ "MyNewEventsRule": { "Properties": { "EventPattern": { - "source": ["aws.ec2"] + "source": [ + "aws.ec2" + ] }, "Name": "mynewabc", "State": "ENABLED", "Targets": [ { "Arn": { - "Fn::GetAtt": ["StateMachine", "Arn"] + "Fn::GetAtt": [ + "StateMachine", + "Arn" + ] }, "Id": "StateMachine", "RoleArn": { - "Fn::GetAtt": ["MyRuleRole", "Arn"] + "Fn::GetAtt": [ + "MyRuleRole", + "Arn" + ] } } ] diff --git a/tests/translator/output/connector_samfunction_to_table.json b/tests/translator/output/connector_samfunction_to_table.json index 18484bbc75..2a1f5bb24e 100644 --- a/tests/translator/output/connector_samfunction_to_table.json +++ b/tests/translator/output/connector_samfunction_to_table.json @@ -1,34 +1,57 @@ { "Resources": { - "MyTable": { - "Type": "AWS::DynamoDB::Table", + "MyConnectorPolicy": { "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "AttributeDefinitions": [ - { - "AttributeName": "Id", - "AttributeType": "S" - } - ], - "KeySchema": [ + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "dynamodb:GetItem", + "dynamodb:Query", + "dynamodb:Scan", + "dynamodb:BatchGetItem", + "dynamodb:ConditionCheckItem", + "dynamodb:PartiQLSelect" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + }, + { + "Fn::Sub": [ + "${DestinationArn}/index/*", + { + "DestinationArn": { + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] + } + } + ] + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ { - "AttributeName": "Id", - "KeyType": "HASH" + "Ref": "MyFunctionRole" } ] - } + }, + "Type": "AWS::IAM::ManagedPolicy" }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "const AWS = require('aws-sdk');\nexports.handler = async (event) => {\n console.log(JSON.stringify(event));\n const docClient = new AWS.DynamoDB.DocumentClient();\n await docClient.scan({ TableName: process.env.TABLE_NAME, }).promise();\n};\n" }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] - }, - "Runtime": "nodejs14.x", "Environment": { "Variables": { "TABLE_NAME": { @@ -36,28 +59,40 @@ } } }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -68,48 +103,26 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", + "MyTable": { "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "dynamodb:GetItem", - "dynamodb:Query", - "dynamodb:Scan", - "dynamodb:BatchGetItem", - "dynamodb:ConditionCheckItem", - "dynamodb:PartiQLSelect" - ], - "Resource": [ - { - "Fn::GetAtt": ["MyTable", "Arn"] - }, - { - "Fn::Sub": [ - "${DestinationArn}/index/*", - { - "DestinationArn": { - "Fn::GetAtt": ["MyTable", "Arn"] - } - } - ] - } - ] - } - ] - }, - "Roles": [ + "AttributeDefinitions": [ { - "Ref": "MyFunctionRole" + "AttributeName": "Id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "Id", + "KeyType": "HASH" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/connector_sfn_to_function.json b/tests/translator/output/connector_sfn_to_function.json index 1558b3b356..a105eece95 100644 --- a/tests/translator/output/connector_sfn_to_function.json +++ b/tests/translator/output/connector_sfn_to_function.json @@ -17,11 +17,17 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeAsync", "lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeAsync", + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } ] } @@ -43,7 +49,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyFunctionRole", "Arn"] + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -60,10 +69,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -102,11 +115,17 @@ }, "DefinitionSubstitutions": { "definition_substitution_1": { - "Fn::GetAtt": ["StateMachineFunction", "Arn"] + "Fn::GetAtt": [ + "StateMachineFunction", + "Arn" + ] } }, "RoleArn": { - "Fn::GetAtt": ["MyStateMachineRole", "Arn"] + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] }, "StateMachineType": "EXPRESS", "Tags": [ @@ -123,10 +142,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["states.amazonaws.com"] + "Service": [ + "states.amazonaws.com" + ] } } ], @@ -138,7 +161,9 @@ "PolicyDocument": { "Statement": [ { - "Action": ["lambda:InvokeFunction"], + "Action": [ + "lambda:InvokeFunction" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ diff --git a/tests/translator/output/connector_sfn_to_sfn.json b/tests/translator/output/connector_sfn_to_sfn.json index b9fb53b4cf..d79e529b0d 100644 --- a/tests/translator/output/connector_sfn_to_sfn.json +++ b/tests/translator/output/connector_sfn_to_sfn.json @@ -1,22 +1,119 @@ { "Resources": { - "TriggerStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "MyConnectorPolicy": { + "Metadata": { + "aws:sam:connectors": { + "MyConnector": { + "Destination": { + "Type": "AWS::Serverless::StateMachine" + }, + "Source": { + "Type": "AWS::Serverless::StateMachine" + } + } + } + }, + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "states:DescribeExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": [ + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", + { + "DestinationName": { + "Fn::GetAtt": [ + "MyStateMachine", + "Name" + ] + } + } + ] + } + ] + }, + { + "Action": [ + "events:DescribeRule" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" + } + ] + }, + { + "Action": [ + "states:StartExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Ref": "MyStateMachine" + } + ] + }, + { + "Action": [ + "states:StopExecution" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": [ + "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", + { + "DestinationName": { + "Fn::GetAtt": [ + "MyStateMachine", + "Name" + ] + } + } + ] + } + ] + }, + { + "Action": [ + "events:PutTargets", + "events:PutRule" + ], + "Effect": "Allow", + "Resource": [ + { + "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" + } + ] + } + ], + "Version": "2012-10-17" + }, + "Roles": [ + { + "Ref": "TriggerStateMachineRole" + } + ] + }, + "Type": "AWS::IAM::ManagedPolicy" + }, + "MyStateMachine": { "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", - " \"StartAt\": \"TryDoSomething\",", + " \"StartAt\": \"Success\",", " \"States\": {", - " \"TryDoSomething\": {", - " \"End\": true,", - " \"Parameters\": {", - " \"StateMachineArn\": \"${definition_substitution_1}\"", - " },", - " \"Resource\": \"arn:aws:states:::states:startExecution.sync:2\",", - " \"Type\": \"Task\"", + " \"Success\": {", + " \"Type\": \"Succeed\"", " }", " }", "}" @@ -25,32 +122,23 @@ }, "RoleArn": { "Fn::GetAtt": [ - "TriggerStateMachineRole", + "MyStateMachineRole", "Arn" ] }, - "StateMachineType": "STANDARD", + "StateMachineType": "EXPRESS", "Tags": [ { "Key": "stateMachine:createdBy", "Value": "SAM" } - ], - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Ref": "MyStateMachine" - } - } + ] }, - "DependsOn": [ - "MyConnectorPolicy" - ] + "Type": "AWS::StepFunctions::StateMachine" }, - "TriggerStateMachineRole": { - "Type": "AWS::IAM::Role", + "MyStateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -63,19 +151,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "TriggerStateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -86,7 +174,8 @@ } } ] - } + }, + "PolicyName": "MyStateMachineRolePolicy0" } ], "Tags": [ @@ -95,46 +184,58 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "TriggerStateMachine": { + "DependsOn": [ + "MyConnectorPolicy" + ], "Properties": { "DefinitionString": { "Fn::Join": [ "\n", [ "{", - " \"StartAt\": \"Success\",", + " \"StartAt\": \"TryDoSomething\",", " \"States\": {", - " \"Success\": {", - " \"Type\": \"Succeed\"", + " \"TryDoSomething\": {", + " \"End\": true,", + " \"Parameters\": {", + " \"StateMachineArn\": \"${definition_substitution_1}\"", + " },", + " \"Resource\": \"arn:aws:states:::states:startExecution.sync:2\",", + " \"Type\": \"Task\"", " }", " }", "}" ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Ref": "MyStateMachine" + } + }, "RoleArn": { "Fn::GetAtt": [ - "MyStateMachineRole", + "TriggerStateMachineRole", "Arn" ] }, - "StateMachineType": "EXPRESS", + "StateMachineType": "STANDARD", "Tags": [ { "Key": "stateMachine:createdBy", "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", + "TriggerStateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -147,19 +248,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "MyStateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { - "Effect": "Allow", "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -170,7 +271,8 @@ } } ] - } + }, + "PolicyName": "TriggerStateMachineRolePolicy0" } ], "Tags": [ @@ -179,110 +281,8 @@ "Value": "SAM" } ] - } - }, - "MyConnectorPolicy": { - "Type": "AWS::IAM::ManagedPolicy", - "Metadata": { - "aws:sam:connectors": { - "MyConnector": { - "Source": { - "Type": "AWS::Serverless::StateMachine" - }, - "Destination": { - "Type": "AWS::Serverless::StateMachine" - } - } - } }, - "Properties": { - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Effect": "Allow", - "Action": [ - "states:DescribeExecution" - ], - "Resource": [ - { - "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", - { - "DestinationName": { - "Fn::GetAtt": [ - "MyStateMachine", - "Name" - ] - } - } - ] - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "events:DescribeRule" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "states:StartExecution" - ], - "Resource": [ - { - "Ref": "MyStateMachine" - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "states:StopExecution" - ], - "Resource": [ - { - "Fn::Sub": [ - "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:execution:${DestinationName}:*", - { - "DestinationName": { - "Fn::GetAtt": [ - "MyStateMachine", - "Name" - ] - } - } - ] - } - ] - }, - { - "Effect": "Allow", - "Action": [ - "events:PutTargets", - "events:PutRule" - ], - "Resource": [ - { - "Fn::Sub": "arn:${AWS::Partition}:events:${AWS::Region}:${AWS::AccountId}:rule/StepFunctionsGetEventsForStepFunctionsExecutionRule" - } - ] - } - ] - }, - "Roles": [ - { - "Ref": "TriggerStateMachineRole" - } - ] - } + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/connector_sns_to_function.json b/tests/translator/output/connector_sns_to_function.json index e5054c69c2..d353e61557 100644 --- a/tests/translator/output/connector_sns_to_function.json +++ b/tests/translator/output/connector_sns_to_function.json @@ -16,7 +16,10 @@ "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { - "Fn::GetAtt": ["MyFunction", "Arn"] + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] }, "Principal": "sns.amazonaws.com", "SourceArn": { @@ -39,7 +42,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, diff --git a/tests/translator/output/connector_sns_to_sqs.json b/tests/translator/output/connector_sns_to_sqs.json index 9b6063a4b9..556f77cd4e 100644 --- a/tests/translator/output/connector_sns_to_sqs.json +++ b/tests/translator/output/connector_sns_to_sqs.json @@ -33,7 +33,10 @@ "Service": "sns.amazonaws.com" }, "Resource": { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] } } ], @@ -80,7 +83,10 @@ "Service": "sns.amazonaws.com" }, "Resource": { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] } } ], @@ -99,13 +105,19 @@ "Subscription": [ { "Endpoint": { - "Fn::GetAtt": ["MyQueue1", "Arn"] + "Fn::GetAtt": [ + "MyQueue1", + "Arn" + ] }, "Protocol": "sqs" }, { "Endpoint": { - "Fn::GetAtt": ["MyQueue2", "Arn"] + "Fn::GetAtt": [ + "MyQueue2", + "Arn" + ] }, "Protocol": "sqs" } diff --git a/tests/translator/output/connector_sqs_to_function.json b/tests/translator/output/connector_sqs_to_function.json index d5d29207ae..e459424f60 100644 --- a/tests/translator/output/connector_sqs_to_function.json +++ b/tests/translator/output/connector_sqs_to_function.json @@ -17,20 +17,31 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:DeleteMessage"], + "Action": [ + "sqs:DeleteMessage" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] } ] }, { - "Action": ["sqs:GetQueueAttributes", "sqs:ReceiveMessage"], + "Action": [ + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" + ], "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] } ] } @@ -59,7 +70,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["InvokedFunctionRole", "Arn"] + "Fn::GetAtt": [ + "InvokedFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -76,10 +90,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -93,14 +111,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -124,11 +147,16 @@ "Type": "AWS::SQS::Queue" }, "SQSEventSourceMapping": { - "DependsOn": ["ConnectorPolicy"], + "DependsOn": [ + "ConnectorPolicy" + ], "Properties": { "BatchSize": 10, "EventSourceArn": { - "Fn::GetAtt": ["Queue", "Arn"] + "Fn::GetAtt": [ + "Queue", + "Arn" + ] }, "FunctionName": { "Ref": "InvokedFunction" @@ -153,7 +181,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["TriggerFunctionRole", "Arn"] + "Fn::GetAtt": [ + "TriggerFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -171,10 +202,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -202,7 +237,10 @@ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -216,14 +254,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["Queue", "QueueName"] + "Fn::GetAtt": [ + "Queue", + "QueueName" + ] } } ] diff --git a/tests/translator/output/connector_table_to_function.json b/tests/translator/output/connector_table_to_function.json index e038dcb2b1..ed90208e1d 100644 --- a/tests/translator/output/connector_table_to_function.json +++ b/tests/translator/output/connector_table_to_function.json @@ -30,7 +30,10 @@ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["MyTable", "Arn"] + "Fn::GetAtt": [ + "MyTable", + "Arn" + ] } } ] @@ -62,7 +65,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["MyRole", "Arn"] + "Fn::GetAtt": [ + "MyRole", + "Arn" + ] }, "Runtime": "nodejs14.x" }, diff --git a/tests/translator/output/connector_table_to_function_read.json b/tests/translator/output/connector_table_to_function_read.json index b0fcad5588..03a7493d11 100644 --- a/tests/translator/output/connector_table_to_function_read.json +++ b/tests/translator/output/connector_table_to_function_read.json @@ -29,14 +29,20 @@ "Effect": "Allow", "Resource": [ { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] }, { "Fn::Sub": [ "${DestinationArn}/index/*", { "DestinationArn": { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] } } ] @@ -84,7 +90,10 @@ "${SourceArn}/stream/*", { "SourceArn": { - "Fn::GetAtt": ["Table", "Arn"] + "Fn::GetAtt": [ + "Table", + "Arn" + ] } } ] @@ -103,15 +112,23 @@ "Type": "AWS::IAM::ManagedPolicy" }, "DynamoDBTableStream": { - "DependsOn": ["ConnectorPolicy"], + "DependsOn": [ + "ConnectorPolicy" + ], "Properties": { "BatchSize": 1, "Enabled": true, "EventSourceArn": { - "Fn::GetAtt": ["Table", "StreamArn"] + "Fn::GetAtt": [ + "Table", + "StreamArn" + ] }, "FunctionName": { - "Fn::GetAtt": ["InvokedFunction", "Arn"] + "Fn::GetAtt": [ + "InvokedFunction", + "Arn" + ] }, "StartingPosition": "TRIM_HORIZON" }, @@ -131,7 +148,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["InvokedFunctionRole", "Arn"] + "Fn::GetAtt": [ + "InvokedFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -148,10 +168,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -165,14 +189,19 @@ "PolicyDocument": { "Statement": [ { - "Action": ["sqs:SendMessage*"], + "Action": [ + "sqs:SendMessage*" + ], "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] @@ -230,7 +259,10 @@ }, "Handler": "index.handler", "Role": { - "Fn::GetAtt": ["TriggerFunctionRole", "Arn"] + "Fn::GetAtt": [ + "TriggerFunctionRole", + "Arn" + ] }, "Runtime": "nodejs14.x", "Tags": [ @@ -248,10 +280,14 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } ], @@ -279,7 +315,10 @@ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { "queueName": { - "Fn::GetAtt": ["VerificationQueue", "QueueName"] + "Fn::GetAtt": [ + "VerificationQueue", + "QueueName" + ] } } ] diff --git a/tests/translator/output/definition_body_intrinsics_support.json b/tests/translator/output/definition_body_intrinsics_support.json index 3d19754b8c..62d3e1d5ea 100644 --- a/tests/translator/output/definition_body_intrinsics_support.json +++ b/tests/translator/output/definition_body_intrinsics_support.json @@ -1,146 +1,146 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", - "Conditions": { - "FalseCondition": { - "Fn::Equals": [ - true, - false - ] + "AWSTemplateFormatVersion": "2010-09-09", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", + "Resources": { + "HttpApiIfIntrinsicAndNoOpenApiEditor": { + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + } + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "openapi": "3.0", + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/" + } + } + } + } + } + ] } + }, + "Type": "AWS::ApiGatewayV2::Api" }, - "Resources": { - "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", - "RestApiId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" - }, - "StageName": "Stage" - } - }, - "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" - }, - "RestApiId": { - "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" - }, - "StageName": "prod" - } - }, - "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" - }, - "StageName": "prod", - "AutoDeploy": true - } + "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { + "Properties": { + "ApiId": { + "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" }, - "RestApiIfIntrinsicAndNoSwaggerEditor": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "Fn::If": [ - "FalseCondition", - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "swagger": "2.0" - }, - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otheruri.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "swagger": "2.0" - } - ] + "AutoDeploy": true, + "StageName": "prod" + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "RestApiIfIntrinsicAndNoSwaggerEditor": { + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" } - } - }, - "HttpApiIfIntrinsicAndNoOpenApiEditor": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "Fn::If": [ - "FalseCondition", - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "openapi": "3.0" - }, - { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Api" - } - }, - "paths": { - "/post": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": "https://www.otheruri.co/", - "payloadFormatVersion": "1.0" - } - } - } - }, - "openapi": "3.0" - } - ] + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/" + } + } + } + }, + "swagger": "2.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/" + } + } } + }, + "swagger": "2.0" } + ] } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { + "Properties": { + "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" + }, + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "prod" + }, + "Type": "AWS::ApiGateway::Stage" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/depends_on.json b/tests/translator/output/depends_on.json index c21c752737..6654df11ec 100644 --- a/tests/translator/output/depends_on.json +++ b/tests/translator/output/depends_on.json @@ -1,7 +1,42 @@ { "Resources": { + "MyExplicitApi": { + "DependsOn": "MySamTable", + "Properties": { + "BodyS3Location": { + "Bucket": "sam-translator-tests-dont-delete", + "Key": "swagger-http.json" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyExplicitApiDeployment74b681ce04": { + "Properties": { + "Description": "RestApi deployment id: 74b681ce04601a2cf69b6d05d53782b216cf96bb", + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyExplicitApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyExplicitApiDeployment74b681ce04" + }, + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", + "DependsOn": [ + "MyExplicitApi", + "MySamTable" + ], "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -17,139 +52,104 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "DependsOn": [ - "MyExplicitApi", - "MySamTable" - ] + "Type": "AWS::Lambda::Function" }, - "MyExplicitApiDeployment74b681ce04": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunctionMyApiPermissiondev": { "Properties": { - "RestApiId": { - "Ref": "MyExplicitApi" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" }, - "Description": "RestApi deployment id: 74b681ce04601a2cf69b6d05d53782b216cf96bb", - "StageName": "Stage" - } + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "MyExplicitApi", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "MyFunctionRole": { "Properties": { - "BodyS3Location": { - "Bucket": "sam-translator-tests-dont-delete", - "Key": "swagger-http.json" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "DependsOn": "MySamTable" + "Type": "AWS::IAM::Role" }, "MyOtherTable": { - "Type": "AWS::DynamoDB::Table", + "DependsOn": "MySamTable", "Properties": { - "KeySchema": [ + "AttributeDefinitions": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "AttributeType": "S" } ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "KeySchema": [ { "AttributeName": "id", - "AttributeType": "S" + "KeyType": "HASH" } ], "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" } }, - "DependsOn": "MySamTable" - }, - "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyExplicitApiDeployment74b681ce04" - }, - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "StageName": "dev" - } + "Type": "AWS::DynamoDB::Table" }, "MySamTable": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": "MyExplicitApi" - } - ] - } - } + }, + "Type": "AWS::DynamoDB::Table" } } } diff --git a/tests/translator/output/error_api_auth_invalid_path_item.json b/tests/translator/output/error_api_auth_invalid_path_item.json index 2d9c180931..319c42351f 100644 --- a/tests/translator/output/error_api_auth_invalid_path_item.json +++ b/tests/translator/output/error_api_auth_invalid_path_item.json @@ -1 +1,3 @@ - {"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/' path must be a dictionary according to Swagger spec."} +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/' path must be a dictionary according to Swagger spec." +} diff --git a/tests/translator/output/error_api_auth_null_path_item.json b/tests/translator/output/error_api_auth_null_path_item.json index 2d9c180931..319c42351f 100644 --- a/tests/translator/output/error_api_auth_null_path_item.json +++ b/tests/translator/output/error_api_auth_null_path_item.json @@ -1 +1,3 @@ - {"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/' path must be a dictionary according to Swagger spec."} +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/' path must be a dictionary according to Swagger spec." +} diff --git a/tests/translator/output/error_api_authorizer_property_indentity_header_with_invalid_type.json b/tests/translator/output/error_api_authorizer_property_indentity_header_with_invalid_type.json index a8cc1d1276..123a392c37 100644 --- a/tests/translator/output/error_api_authorizer_property_indentity_header_with_invalid_type.json +++ b/tests/translator/output/error_api_authorizer_property_indentity_header_with_invalid_type.json @@ -1,8 +1,8 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property identity's 'Headers' is of invalid type.", - "errors": [ - { - "errorMessage": "Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property identity's 'Headers' is of invalid type." - } - ] -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property identity's 'Headers' is of invalid type.", + "errors": [ + { + "errorMessage": "Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property identity's 'Headers' is of invalid type." + } + ] +} diff --git a/tests/translator/output/error_api_authorizer_property_indentity_with_invalid_type.json b/tests/translator/output/error_api_authorizer_property_indentity_with_invalid_type.json index 2b13c15b2a..17abdaf99d 100644 --- a/tests/translator/output/error_api_authorizer_property_indentity_with_invalid_type.json +++ b/tests/translator/output/error_api_authorizer_property_indentity_with_invalid_type.json @@ -1,8 +1,8 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property 'identity' is of invalid type.", - "errors": [ - { - "errorMessage": "Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property 'identity' is of invalid type." - } - ] -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property 'identity' is of invalid type.", + "errors": [ + { + "errorMessage": "Resource with id [MyApi] is invalid. MyLambdaAuthUpdated Lambda Authorizer property 'identity' is of invalid type." + } + ] +} diff --git a/tests/translator/output/error_api_duplicate_methods_same_path.json b/tests/translator/output/error_api_duplicate_methods_same_path.json index 81d9ee856e..9fff8aaaa2 100644 --- a/tests/translator/output/error_api_duplicate_methods_same_path.json +++ b/tests/translator/output/error_api_duplicate_methods_same_path.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function2] is invalid. Event with id [GetHtml] is invalid. API method \"post\" defined multiple times for path \"/add\".", "errors": [ { "errorMessage": "Resource with id [Function2] is invalid. Event with id [GetHtml] is invalid. API method \"post\" defined multiple times for path \"/add\"." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function2] is invalid. Event with id [GetHtml] is invalid. API method \"post\" defined multiple times for path \"/add\"." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_api_event_import_vaule_reference.json b/tests/translator/output/error_api_event_import_vaule_reference.json index 83b444b464..c15d26e6c1 100644 --- a/tests/translator/output/error_api_event_import_vaule_reference.json +++ b/tests/translator/output/error_api_event_import_vaule_reference.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template."} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_event_ref_http_api.json b/tests/translator/output/error_api_event_ref_http_api.json index 9af004dd4a..1b455d9988 100644 --- a/tests/translator/output/error_api_event_ref_http_api.json +++ b/tests/translator/output/error_api_event_ref_http_api.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [Event1] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template."} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [Event1] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template." +} diff --git a/tests/translator/output/error_api_gateway_responses_nonnumeric_status_code.json b/tests/translator/output/error_api_gateway_responses_nonnumeric_status_code.json index 3a404715c9..2465346b8b 100644 --- a/tests/translator/output/error_api_gateway_responses_nonnumeric_status_code.json +++ b/tests/translator/output/error_api_gateway_responses_nonnumeric_status_code.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Property 'StatusCode' must be numeric"} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Property 'StatusCode' must be numeric" +} diff --git a/tests/translator/output/error_api_gateway_responses_unknown_responseparameter.json b/tests/translator/output/error_api_gateway_responses_unknown_responseparameter.json index 503194edc8..ae31d40a2a 100644 --- a/tests/translator/output/error_api_gateway_responses_unknown_responseparameter.json +++ b/tests/translator/output/error_api_gateway_responses_unknown_responseparameter.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Invalid gateway response parameter 'Footers'"} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Invalid gateway response parameter 'Footers'" +} diff --git a/tests/translator/output/error_api_gateway_responses_unknown_responseparameter_property.json b/tests/translator/output/error_api_gateway_responses_unknown_responseparameter_property.json index 62fd4320f5..061d578c07 100644 --- a/tests/translator/output/error_api_gateway_responses_unknown_responseparameter_property.json +++ b/tests/translator/output/error_api_gateway_responses_unknown_responseparameter_property.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Invalid property 'SubStatusCode' in 'GatewayResponses' property 'UNAUTHORIZED'."} +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Invalid property 'SubStatusCode' in 'GatewayResponses' property 'UNAUTHORIZED'." +} diff --git a/tests/translator/output/error_api_invalid_auth_identity_cognito.json b/tests/translator/output/error_api_invalid_auth_identity_cognito.json index 87f756a929..a18cdd3ad0 100644 --- a/tests/translator/output/error_api_invalid_auth_identity_cognito.json +++ b/tests/translator/output/error_api_invalid_auth_identity_cognito.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ServerlessApi] is invalid. Auth.Authorizers..Identity must be a dict (LambdaTokenAuthorizationIdentity, LambdaRequestAuthorizationIdentity or CognitoAuthorizationIdentity).", "errors": [ { "errorMessage": "Resource with id [ServerlessApi] is invalid. Auth.Authorizers..Identity must be a dict (LambdaTokenAuthorizationIdentity, LambdaRequestAuthorizationIdentity or CognitoAuthorizationIdentity)." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ServerlessApi] is invalid. Auth.Authorizers..Identity must be a dict (LambdaTokenAuthorizationIdentity, LambdaRequestAuthorizationIdentity or CognitoAuthorizationIdentity)." + ] } diff --git a/tests/translator/output/error_api_invalid_auth_identity_lambda_request.json b/tests/translator/output/error_api_invalid_auth_identity_lambda_request.json index 87f756a929..a18cdd3ad0 100644 --- a/tests/translator/output/error_api_invalid_auth_identity_lambda_request.json +++ b/tests/translator/output/error_api_invalid_auth_identity_lambda_request.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ServerlessApi] is invalid. Auth.Authorizers..Identity must be a dict (LambdaTokenAuthorizationIdentity, LambdaRequestAuthorizationIdentity or CognitoAuthorizationIdentity).", "errors": [ { "errorMessage": "Resource with id [ServerlessApi] is invalid. Auth.Authorizers..Identity must be a dict (LambdaTokenAuthorizationIdentity, LambdaRequestAuthorizationIdentity or CognitoAuthorizationIdentity)." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ServerlessApi] is invalid. Auth.Authorizers..Identity must be a dict (LambdaTokenAuthorizationIdentity, LambdaRequestAuthorizationIdentity or CognitoAuthorizationIdentity)." + ] } diff --git a/tests/translator/output/error_api_invalid_definitionbody.json b/tests/translator/output/error_api_invalid_definitionbody.json index fefa4314ff..8f7054e7af 100644 --- a/tests/translator/output/error_api_invalid_definitionbody.json +++ b/tests/translator/output/error_api_invalid_definitionbody.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiWithInvalidBodyType] is invalid. Type of property 'DefinitionBody' is invalid.", "errors": [ { "errorMessage": "Resource with id [ApiWithInvalidBodyType] is invalid. Type of property 'DefinitionBody' is invalid." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiWithInvalidBodyType] is invalid. Type of property 'DefinitionBody' is invalid." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_api_invalid_definitionuri.json b/tests/translator/output/error_api_invalid_definitionuri.json index 22a6e777eb..6c9ccad1fd 100644 --- a/tests/translator/output/error_api_invalid_definitionuri.json +++ b/tests/translator/output/error_api_invalid_definitionuri.json @@ -1,4 +1,5 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both.", "errors": [ { "errorMessage": "Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter." @@ -6,6 +7,5 @@ { "errorMessage": "Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [Api] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [ApiWithBodyAndDefinitionUri] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both." + ] } diff --git a/tests/translator/output/error_api_invalid_event_authorizer_type.json b/tests/translator/output/error_api_invalid_event_authorizer_type.json index 2bce26ea7e..a013731ee8 100644 --- a/tests/translator/output/error_api_invalid_event_authorizer_type.json +++ b/tests/translator/output/error_api_invalid_event_authorizer_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AuthorizedApi] is invalid. Authorizers must be a dictionary. Resource with id [SignInFunction] is invalid. Event with id [MainFuncPostV1] is invalid. Unable to set Authorizer [['CognitoAuthorizer']] on API method [post] for path [/v1/signin]. The method authorizer must be a string with a corresponding dict entry in the api authorizer.", "errors": [ { "errorMessage": "Resource with id [AuthorizedApi] is invalid. Authorizers must be a dictionary. Resource with id [SignInFunction] is invalid. Event with id [MainFuncPostV1] is invalid. Unable to set Authorizer [['CognitoAuthorizer']] on API method [post] for path [/v1/signin]. The method authorizer must be a string with a corresponding dict entry in the api authorizer." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AuthorizedApi] is invalid. Authorizers must be a dictionary. Resource with id [SignInFunction] is invalid. Event with id [MainFuncPostV1] is invalid. Unable to set Authorizer [['CognitoAuthorizer']] on API method [post] for path [/v1/signin]. The method authorizer must be a string with a corresponding dict entry in the api authorizer." + ] } diff --git a/tests/translator/output/error_api_invalid_fail_on_warnings.json b/tests/translator/output/error_api_invalid_fail_on_warnings.json index 4f7a202c77..3999eec810 100644 --- a/tests/translator/output/error_api_invalid_fail_on_warnings.json +++ b/tests/translator/output/error_api_invalid_fail_on_warnings.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [ApiGatewayApi] is invalid. FailOnWarnings cannot be empty." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayApi] is invalid. Type of property 'FailOnWarnings' is invalid." - } \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayApi] is invalid. Type of property 'FailOnWarnings' is invalid.", + "errors": [ + { + "errorMessage": "Resource with id [ApiGatewayApi] is invalid. FailOnWarnings cannot be empty." + } + ] +} diff --git a/tests/translator/output/error_api_invalid_openapi_path.json b/tests/translator/output/error_api_invalid_openapi_path.json index 2aedc06844..54228b95b2 100644 --- a/tests/translator/output/error_api_invalid_openapi_path.json +++ b/tests/translator/output/error_api_invalid_openapi_path.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/foo' path must be a dictionary according to Swagger spec." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_invalid_openapi_path_with_empty_responses.json b/tests/translator/output/error_api_invalid_openapi_path_with_empty_responses.json index 73a7f49ac3..d1e27f3372 100644 --- a/tests/translator/output/error_api_invalid_openapi_path_with_empty_responses.json +++ b/tests/translator/output/error_api_invalid_openapi_path_with_empty_responses.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of responses in options method for path /foo must be a dictionary according to Swagger spec." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_invalid_openapi_path_with_string_responses.json b/tests/translator/output/error_api_invalid_openapi_path_with_string_responses.json index 73a7f49ac3..d1e27f3372 100644 --- a/tests/translator/output/error_api_invalid_openapi_path_with_string_responses.json +++ b/tests/translator/output/error_api_invalid_openapi_path_with_string_responses.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of responses in options method for path /foo must be a dictionary according to Swagger spec." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_invalid_path.json b/tests/translator/output/error_api_invalid_path.json index 2aedc06844..54228b95b2 100644 --- a/tests/translator/output/error_api_invalid_path.json +++ b/tests/translator/output/error_api_invalid_path.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/foo' path must be a dictionary according to Swagger spec." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_invalid_restapiid.json b/tests/translator/output/error_api_invalid_restapiid.json index aa4c86aa1d..ac03db210a 100644 --- a/tests/translator/output/error_api_invalid_restapiid.json +++ b/tests/translator/output/error_api_invalid_restapiid.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionWithNonExistentApiReference] is invalid. Event with id [GetHtml] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template.", "errors": [ { "errorMessage": "Resource with id [FunctionWithNonExistentApiReference] is invalid. Event with id [GetHtml] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionWithNonExistentApiReference] is invalid. Event with id [GetHtml] is invalid. RestApiId must be a valid reference to an 'AWS::Serverless::Api' resource in same template." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_api_invalid_stagename.json b/tests/translator/output/error_api_invalid_stagename.json index 1076d671f3..89002f58a3 100644 --- a/tests/translator/output/error_api_invalid_stagename.json +++ b/tests/translator/output/error_api_invalid_stagename.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiWithEmptyStageName] is invalid. StageName cannot be empty.", "errors": [ { "errorMessage": "Resource with id [ApiWithEmptyStageName] is invalid. StageName cannot be empty." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiWithEmptyStageName] is invalid. StageName cannot be empty." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_api_invalid_usage_plan.json b/tests/translator/output/error_api_invalid_usage_plan.json index 711e4649dd..ba66f8848d 100644 --- a/tests/translator/output/error_api_invalid_usage_plan.json +++ b/tests/translator/output/error_api_invalid_usage_plan.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApiWithCognitoAuth] is invalid. 'UsagePlan' must be a dictionary", "errors": [ { "errorMessage": "Resource with id [MyApiWithCognitoAuth] is invalid. 'UsagePlan' must be a dictionary" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApiWithCognitoAuth] is invalid. 'UsagePlan' must be a dictionary" + ] } diff --git a/tests/translator/output/error_api_mtls_configuration_invalid_field.json b/tests/translator/output/error_api_mtls_configuration_invalid_field.json index ffbf6bf736..c24aa1fa9b 100644 --- a/tests/translator/output/error_api_mtls_configuration_invalid_field.json +++ b/tests/translator/output/error_api_mtls_configuration_invalid_field.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [WrongTruststoreUri] is invalid. Available MutualTlsAuthentication fields are ['TruststoreUri', 'TruststoreVersion'].", "errors": [ { "errorMessage": "Resource with id [WrongTruststoreUri] is invalid. MutualTlsAuthentication must contains one of the following fields ['TruststoreUri', 'TruststoreVersion']." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [WrongTruststoreUri] is invalid. Available MutualTlsAuthentication fields are ['TruststoreUri', 'TruststoreVersion']." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_api_mtls_configuration_invalid_type.json b/tests/translator/output/error_api_mtls_configuration_invalid_type.json index 28b0e56bff..6b2026623d 100644 --- a/tests/translator/output/error_api_mtls_configuration_invalid_type.json +++ b/tests/translator/output/error_api_mtls_configuration_invalid_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [['TruststoreUri', 'TruststoreVersion']] is invalid. MutualTlsAuthentication must be a map with at least one of the following fields ['TruststoreUri', 'TruststoreVersion'].", "errors": [ { "errorMessage": "Resource with id [['TruststoreUri', 'TruststoreVersion']] is invalid. MutualTlsAuthentication must contains one of the following fields ['TruststoreUri', 'TruststoreVersion']." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [['TruststoreUri', 'TruststoreVersion']] is invalid. MutualTlsAuthentication must be a map with at least one of the following fields ['TruststoreUri', 'TruststoreVersion']." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_api_no_cors_invalid_openapi_null_path.json b/tests/translator/output/error_api_no_cors_invalid_openapi_null_path.json index 2aedc06844..54228b95b2 100644 --- a/tests/translator/output/error_api_no_cors_invalid_openapi_null_path.json +++ b/tests/translator/output/error_api_no_cors_invalid_openapi_null_path.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/foo' path must be a dictionary according to Swagger spec." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_no_cors_invalid_openapi_string_path.json b/tests/translator/output/error_api_no_cors_invalid_openapi_string_path.json index 2aedc06844..54228b95b2 100644 --- a/tests/translator/output/error_api_no_cors_invalid_openapi_string_path.json +++ b/tests/translator/output/error_api_no_cors_invalid_openapi_string_path.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of '/foo' path must be a dictionary according to Swagger spec." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_swagger_integration_with_condition_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_condition_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_condition_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_condition_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_swagger_integration_with_find_in_map_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_find_in_map_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_find_in_map_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_find_in_map_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_swagger_integration_with_getatt_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_getatt_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_getatt_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_getatt_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_swagger_integration_with_join_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_join_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_join_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_join_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_swagger_integration_with_select_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_select_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_select_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_select_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_swagger_integration_with_sub_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_sub_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_sub_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_sub_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_swagger_integration_with_transform_intrinsic_api_id.json b/tests/translator/output/error_api_swagger_integration_with_transform_intrinsic_api_id.json index fd1abe8a31..5acf3e4088 100644 --- a/tests/translator/output/error_api_swagger_integration_with_transform_intrinsic_api_id.json +++ b/tests/translator/output/error_api_swagger_integration_with_transform_intrinsic_api_id.json @@ -1,4 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." - } - \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." +} diff --git a/tests/translator/output/error_api_with_cors_and_empty_allow_origin.json b/tests/translator/output/error_api_with_cors_and_empty_allow_origin.json index a02f7b505a..1febed40ca 100644 --- a/tests/translator/output/error_api_with_cors_and_empty_allow_origin.json +++ b/tests/translator/output/error_api_with_cors_and_empty_allow_origin.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Structure of the SAM template is invalid. Invalid input. Value for AllowedOrigins is required", "errors": [ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Structure of the SAM template is invalid. Invalid input. Value for AllowedOrigins is required" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Structure of the SAM template is invalid. Invalid input. Value for AllowedOrigins is required" + ] } diff --git a/tests/translator/output/error_api_with_custom_domains_invalid.json b/tests/translator/output/error_api_with_custom_domains_invalid.json index 111c9b36e0..97a9e92c3b 100644 --- a/tests/translator/output/error_api_with_custom_domains_invalid.json +++ b/tests/translator/output/error_api_with_custom_domains_invalid.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [ServerlessRestApi] is invalid. Custom Domains only works if both DomainName and CertificateArn are provided.", "errors": [ { "errorMessage": "Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [ServerlessRestApi] is invalid. Custom Domains only works if both DomainName and CertificateArn are provided." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi] is invalid. EndpointConfiguration for Custom Domains must be one of ['EDGE', 'REGIONAL', 'PRIVATE']. Resource with id [ServerlessRestApi] is invalid. Custom Domains only works if both DomainName and CertificateArn are provided." + ] } diff --git a/tests/translator/output/error_api_with_custom_domains_route53_invalid.json b/tests/translator/output/error_api_with_custom_domains_route53_invalid.json index 1e55a56556..e76c49b31f 100644 --- a/tests/translator/output/error_api_with_custom_domains_route53_invalid.json +++ b/tests/translator/output/error_api_with_custom_domains_route53_invalid.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. HostedZoneId or HostedZoneName is required to enable Route53 support on Custom Domains.", "errors": [ { "errorMessage": "Resource with id [MyApi] is invalid. HostedZoneId is required to enable Route53 support on Custom Domains." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. HostedZoneId or HostedZoneName is required to enable Route53 support on Custom Domains." + ] } diff --git a/tests/translator/output/error_api_with_custom_domains_route53_invalid_type.json b/tests/translator/output/error_api_with_custom_domains_route53_invalid_type.json index 9df5d929ed..9b00d15557 100644 --- a/tests/translator/output/error_api_with_custom_domains_route53_invalid_type.json +++ b/tests/translator/output/error_api_with_custom_domains_route53_invalid_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Invalid property type 'Py27UniStr' for Route53. Expected a map defines an Amazon Route 53 configuration'.", "errors": [ { "errorMessage": "Resource with id [MyApi] is invalid. Invalid property type 'Py27UniStr' for Route53. Expected a map defines an Amazon Route 53 configuration'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Invalid property type 'Py27UniStr' for Route53. Expected a map defines an Amazon Route 53 configuration'." + ] } diff --git a/tests/translator/output/error_api_with_disable_api_execute_endpoint_false.json b/tests/translator/output/error_api_with_disable_api_execute_endpoint_false.json index 5adf87eaf6..822bd5c179 100644 --- a/tests/translator/output/error_api_with_disable_api_execute_endpoint_false.json +++ b/tests/translator/output/error_api_with_disable_api_execute_endpoint_false.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayApi] is invalid. DisableExecuteApiEndpoint works only within 'DefinitionBody' property." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_with_invalid_auth_scopes_openapi.json b/tests/translator/output/error_api_with_invalid_auth_scopes_openapi.json index 35190ce6b4..2d7f6ae50a 100644 --- a/tests/translator/output/error_api_with_invalid_auth_scopes_openapi.json +++ b/tests/translator/output/error_api_with_invalid_auth_scopes_openapi.json @@ -1,9 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [MyApiWithCognitoAuth] is invalid. AuthorizationScopes must be a list." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApiWithCognitoAuth] is invalid. AuthorizationScopes must be a list. Resource with id [MyFn] is invalid. Event with id [CognitoAuthorizerNotString] is invalid. Unable to set Authorizer [['NotString']] on API method [get] for path [/cognitoauthorizernotstring]. The method authorizer must be a string with a corresponding dict entry in the api authorizer." - } - + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApiWithCognitoAuth] is invalid. AuthorizationScopes must be a list. Resource with id [MyFn] is invalid. Event with id [CognitoAuthorizerNotString] is invalid. Unable to set Authorizer [['NotString']] on API method [get] for path [/cognitoauthorizernotstring]. The method authorizer must be a string with a corresponding dict entry in the api authorizer.", + "errors": [ + { + "errorMessage": "Resource with id [MyApiWithCognitoAuth] is invalid. AuthorizationScopes must be a list." + } + ] +} diff --git a/tests/translator/output/error_api_with_invalid_open_api_version.json b/tests/translator/output/error_api_with_invalid_open_api_version.json index e5b5c73a5a..9712351729 100644 --- a/tests/translator/output/error_api_with_invalid_open_api_version.json +++ b/tests/translator/output/error_api_with_invalid_open_api_version.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [MyApi] is invalid. The OpenApiVersion value must be of the format '3.0.0'." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. The OpenApiVersion value must be of the format '3.0.0'." - } + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. The OpenApiVersion value must be of the format '3.0.0'.", + "errors": [ + { + "errorMessage": "Resource with id [MyApi] is invalid. The OpenApiVersion value must be of the format '3.0.0'." + } + ] +} diff --git a/tests/translator/output/error_api_with_invalid_open_api_version_type.json b/tests/translator/output/error_api_with_invalid_open_api_version_type.json index c1c05322d9..50d73eef1f 100644 --- a/tests/translator/output/error_api_with_invalid_open_api_version_type.json +++ b/tests/translator/output/error_api_with_invalid_open_api_version_type.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [MyApi] is invalid. Type of property 'OpenApiVersion' is invalid." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Type of property 'OpenApiVersion' is invalid." - } \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Type of property 'OpenApiVersion' is invalid.", + "errors": [ + { + "errorMessage": "Resource with id [MyApi] is invalid. Type of property 'OpenApiVersion' is invalid." + } + ] +} diff --git a/tests/translator/output/error_api_with_models_of_invalid_type.json b/tests/translator/output/error_api_with_models_of_invalid_type.json index 1f00f57332..a458b9df9d 100644 --- a/tests/translator/output/error_api_with_models_of_invalid_type.json +++ b/tests/translator/output/error_api_with_models_of_invalid_type.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi] is invalid. Type of property 'Models' is invalid. Resource with id [MyFunction] is invalid. Event with id [None] is invalid. Unable to set RequestModel [User] on API method [get] for path [/none] because the related API Models defined is of invalid type." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_api_with_usage_plan_invalid_parameter.json b/tests/translator/output/error_api_with_usage_plan_invalid_parameter.json index c5f06ba39a..1591492b06 100644 --- a/tests/translator/output/error_api_with_usage_plan_invalid_parameter.json +++ b/tests/translator/output/error_api_with_usage_plan_invalid_parameter.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApiOne] is invalid. Invalid property for 'UsagePlan'", "errors": [ { "errorMessage": "\"Resource with id [MyApiOne] is invalid. Invalid property for 'UsagePlan'\"" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApiOne] is invalid. Invalid property for 'UsagePlan'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_application_does_not_exist.json b/tests/translator/output/error_application_does_not_exist.json index 9c5be4471c..5c823c4584 100644 --- a/tests/translator/output/error_application_does_not_exist.json +++ b/tests/translator/output/error_application_does_not_exist.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApplication] is invalid. Cannot access application: non-existent.", "errors": [ { "errorMessage": "Resource with id [MyApplication] is invalid. Cannot access application: non-existent." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApplication] is invalid. Cannot access application: non-existent." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_application_no_access.json b/tests/translator/output/error_application_no_access.json index 7900c27312..9314935a4f 100644 --- a/tests/translator/output/error_application_no_access.json +++ b/tests/translator/output/error_application_no_access.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [InvalidSemver] is invalid. Cannot access application: invalid-semver. Resource with id [NoAccess] is invalid. Cannot access application: no-access. Resource with id [NonExistent] is invalid. Cannot access application: non-existent.", "errors": [ { "errorMessage": "Resource with id [InvalidSemver] is invalid. Cannot access application: invalid-semver. Resource with id [NoAccess] is invalid. Cannot access application: no-access. Resource with id [NonExistent] is invalid. Cannot access application: non-existent." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [InvalidSemver] is invalid. Cannot access application: invalid-semver. Resource with id [NoAccess] is invalid. Cannot access application: no-access. Resource with id [NonExistent] is invalid. Cannot access application: non-existent." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_application_preparing_timeout.json b/tests/translator/output/error_application_preparing_timeout.json index 58ac8e8217..3fd0ffc52f 100644 --- a/tests/translator/output/error_application_preparing_timeout.json +++ b/tests/translator/output/error_application_preparing_timeout.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [['preparing-never-ready']] is invalid. Timed out waiting for nested stack templates to reach ACTIVE status.", "errors": [ { "errorMessage": "Resource with id [['preparing-never-ready']] is invalid. Timed out waiting for nested stack templates to reach ACTIVE status." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [['preparing-never-ready']] is invalid. Timed out waiting for nested stack templates to reach ACTIVE status." + ] } diff --git a/tests/translator/output/error_application_properties.json b/tests/translator/output/error_application_properties.json index 1bf6109811..555b567eb5 100644 --- a/tests/translator/output/error_application_properties.json +++ b/tests/translator/output/error_application_properties.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 7. Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [IntrinsicProperties] is invalid. Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property.", "errors": [ { "errorMessage": "Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [IntrinsicProperties] is invalid. Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 7. Resource with id [BlankProperties] is invalid. Property 'ApplicationId' cannot be blank. Resource with id [IntrinsicProperties] is invalid. Property 'ApplicationId' cannot be resolved. Only FindInMap and Ref intrinsic functions are supported. Resource with id [MissingApplicationId] is invalid. Resource is missing the required [ApplicationId] property. Resource with id [MissingLocation] is invalid. Resource is missing the required [Location] property. Resource with id [MissingSemanticVersion] is invalid. Resource is missing the required [SemanticVersion] property. Resource with id [NormalApplication] is invalid. Type of property 'ApplicationId' is invalid. Resource with id [UnsupportedProperty] is invalid. Resource is missing the required [Location] property." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_auto_publish_alias_empty_string.json b/tests/translator/output/error_auto_publish_alias_empty_string.json index 46183aa608..dc60ec505e 100644 --- a/tests/translator/output/error_auto_publish_alias_empty_string.json +++ b/tests/translator/output/error_auto_publish_alias_empty_string.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. 'DeploymentPreference' requires AutoPublishAlias property to be specified." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. 'DeploymentPreference' requires AutoPublishAlias property to be specified." +} diff --git a/tests/translator/output/error_cognito_trigger_invalid_type.json b/tests/translator/output/error_cognito_trigger_invalid_type.json index 1a9bbdd385..f351464554 100644 --- a/tests/translator/output/error_cognito_trigger_invalid_type.json +++ b/tests/translator/output/error_cognito_trigger_invalid_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ImplicitApiFunctionOneTrigger] is invalid. Type of property 'Trigger' is invalid.", "errors": [ { "errorMessage": "Resource with id [ImplicitApiFunctionOneTrigger] is invalid. Type of property 'Trigger' is invalid." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ImplicitApiFunctionOneTrigger] is invalid. Type of property 'Trigger' is invalid." + ] } diff --git a/tests/translator/output/error_cognito_userpool_duplicate_trigger.json b/tests/translator/output/error_cognito_userpool_duplicate_trigger.json index 1bb0d28c72..bd6170cf1c 100644 --- a/tests/translator/output/error_cognito_userpool_duplicate_trigger.json +++ b/tests/translator/output/error_cognito_userpool_duplicate_trigger.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ImplicitApiFunction] is invalid. Event with id [TwoTrigger] is invalid. Cognito trigger \"PreSignUp\" defined multiple times.", "errors": [ { "errorMessage": "Resource with id [ImplicitApiFunction] is invalid. Event with id [TwoTrigger] is invalid. Cognito trigger \"PreSignUp\" defined multiple times." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ImplicitApiFunction] is invalid. Event with id [TwoTrigger] is invalid. Cognito trigger \"PreSignUp\" defined multiple times." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_cognito_userpool_not_string.json b/tests/translator/output/error_cognito_userpool_not_string.json index e9d8c97520..e9a1bad493 100644 --- a/tests/translator/output/error_cognito_userpool_not_string.json +++ b/tests/translator/output/error_cognito_userpool_not_string.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ImplicitApiFunction] is invalid. Event with id [ImplicitApiFunctionOneTrigger] is invalid. Ref in Userpool is not a string." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_connector.json b/tests/translator/output/error_connector.json index 130e3c6607..4c6fd76ad1 100644 --- a/tests/translator/output/error_connector.json +++ b/tests/translator/output/error_connector.json @@ -1,53 +1,53 @@ { - "errors": [ - { - "errorMessage": "Resource with id [NoIdMissingType] is invalid. 'Type' is missing or not a string." - }, - { - "errorMessage": "Resource with id [NonStrId] is invalid. 'Id' is missing or not a string." - }, - { - "errorMessage": "Resource with id [NonExistentLogicalId] is invalid. Unable to find resource with logical ID 'ThisDoesntExist'." - }, - { - "errorMessage": "Resource with id [ResourceWithoutType] is invalid. 'Type' is missing or not a string." - }, - { - "errorMessage": "Resource with id [UnsupportedType] is invalid. Unable to create connector from AWS::Fancy::CoolType to AWS::Lambda::Function; it's not supported or the template is invalid." - }, - { - "errorMessage": "Resource with id [UnsupportedAccessCategory] is invalid. Unsupported 'Permissions' provided; valid values are: Read, Write." - }, - { - "errorMessage": "Resource with id [UnsupportedAccessCategoryCombination] is invalid. Unsupported 'Permissions' provided; valid combinations are: Read + Write." - }, - { - "errorMessage": "Resource with id [MissingRole] is invalid. Unable to get IAM role name from 'Source' resource." - }, - { - "errorMessage": "Resource with id [MissingRoleDestination] is invalid. Unable to get IAM role name from 'Destination' resource." - }, - { - "errorMessage": "Resource with id [MissingSqsQueueUrl] is invalid. Destination.Arn is missing." - }, - { - "errorMessage": "Resource with id [MissingLambdaFunctionArn] is invalid. Source.Arn is missing." - }, - { - "errorMessage": "Resource with id [MissingSnsTopicArn] is invalid. Destination.Arn is missing." - }, - { - "errorMessage": "Resource with id [BothIdAndOtherProps] is invalid. Must provide either 'Id' or a combination of the other properties, not both." - }, - { - "errorMessage": "Resource with id [NoPermissionConnector] is invalid. Missing required property 'Permissions'" - }, - { - "errorMessage": "Resource with id [EmptyPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector" - }, - { - "errorMessage": "Resource with id [EmptyListPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector" - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 16. Resource with id [BothIdAndOtherProps] is invalid. Must provide either 'Id' or a combination of the other properties, not both. Resource with id [EmptyListPermissionConnector] is invalid. 'Permissions' cannot be empty; valid values are: Read, Write. Resource with id [EmptyPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [MissingLambdaFunctionArn] is invalid. Source.Arn is missing. Resource with id [MissingRole] is invalid. Unable to get IAM role name from 'Source' resource. Resource with id [MissingRoleDestination] is invalid. Unable to get IAM role name from 'Destination' resource. Resource with id [MissingSnsTopicArn] is invalid. Destination.Arn is missing. Resource with id [MissingSqsQueueUrl] is invalid. Destination.Arn is missing. Resource with id [NoIdMissingType] is invalid. 'Type' is missing or not a string. Resource with id [NoPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [NonExistentLogicalId] is invalid. Unable to find resource with logical ID 'ThisDoesntExist'. Resource with id [NonStrId] is invalid. 'Id' is missing or not a string. Resource with id [ResourceWithoutType] is invalid. 'Type' is missing or not a string. Resource with id [UnsupportedAccessCategory] is invalid. Unsupported 'Permissions' provided; valid values are: Read, Write. Resource with id [UnsupportedAccessCategoryCombination] is invalid. Unsupported 'Permissions' provided; valid combinations are: Read + Write. Resource with id [UnsupportedType] is invalid. Unable to create connector from AWS::Fancy::CoolType to AWS::Lambda::Function; it's not supported or the template is invalid." - } \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 16. Resource with id [BothIdAndOtherProps] is invalid. Must provide either 'Id' or a combination of the other properties, not both. Resource with id [EmptyListPermissionConnector] is invalid. 'Permissions' cannot be empty; valid values are: Read, Write. Resource with id [EmptyPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [MissingLambdaFunctionArn] is invalid. Source.Arn is missing. Resource with id [MissingRole] is invalid. Unable to get IAM role name from 'Source' resource. Resource with id [MissingRoleDestination] is invalid. Unable to get IAM role name from 'Destination' resource. Resource with id [MissingSnsTopicArn] is invalid. Destination.Arn is missing. Resource with id [MissingSqsQueueUrl] is invalid. Destination.Arn is missing. Resource with id [NoIdMissingType] is invalid. 'Type' is missing or not a string. Resource with id [NoPermissionConnector] is invalid. Missing required property 'Permissions'. Resource with id [NonExistentLogicalId] is invalid. Unable to find resource with logical ID 'ThisDoesntExist'. Resource with id [NonStrId] is invalid. 'Id' is missing or not a string. Resource with id [ResourceWithoutType] is invalid. 'Type' is missing or not a string. Resource with id [UnsupportedAccessCategory] is invalid. Unsupported 'Permissions' provided; valid values are: Read, Write. Resource with id [UnsupportedAccessCategoryCombination] is invalid. Unsupported 'Permissions' provided; valid combinations are: Read + Write. Resource with id [UnsupportedType] is invalid. Unable to create connector from AWS::Fancy::CoolType to AWS::Lambda::Function; it's not supported or the template is invalid.", + "errors": [ + { + "errorMessage": "Resource with id [NoIdMissingType] is invalid. 'Type' is missing or not a string." + }, + { + "errorMessage": "Resource with id [NonStrId] is invalid. 'Id' is missing or not a string." + }, + { + "errorMessage": "Resource with id [NonExistentLogicalId] is invalid. Unable to find resource with logical ID 'ThisDoesntExist'." + }, + { + "errorMessage": "Resource with id [ResourceWithoutType] is invalid. 'Type' is missing or not a string." + }, + { + "errorMessage": "Resource with id [UnsupportedType] is invalid. Unable to create connector from AWS::Fancy::CoolType to AWS::Lambda::Function; it's not supported or the template is invalid." + }, + { + "errorMessage": "Resource with id [UnsupportedAccessCategory] is invalid. Unsupported 'Permissions' provided; valid values are: Read, Write." + }, + { + "errorMessage": "Resource with id [UnsupportedAccessCategoryCombination] is invalid. Unsupported 'Permissions' provided; valid combinations are: Read + Write." + }, + { + "errorMessage": "Resource with id [MissingRole] is invalid. Unable to get IAM role name from 'Source' resource." + }, + { + "errorMessage": "Resource with id [MissingRoleDestination] is invalid. Unable to get IAM role name from 'Destination' resource." + }, + { + "errorMessage": "Resource with id [MissingSqsQueueUrl] is invalid. Destination.Arn is missing." + }, + { + "errorMessage": "Resource with id [MissingLambdaFunctionArn] is invalid. Source.Arn is missing." + }, + { + "errorMessage": "Resource with id [MissingSnsTopicArn] is invalid. Destination.Arn is missing." + }, + { + "errorMessage": "Resource with id [BothIdAndOtherProps] is invalid. Must provide either 'Id' or a combination of the other properties, not both." + }, + { + "errorMessage": "Resource with id [NoPermissionConnector] is invalid. Missing required property 'Permissions'" + }, + { + "errorMessage": "Resource with id [EmptyPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector" + }, + { + "errorMessage": "Resource with id [EmptyListPermissionConnector] is invalid. property Permission not defined for resource of type AWS::Serverless::Connector" + } + ] +} diff --git a/tests/translator/output/error_consumer_group_id.json b/tests/translator/output/error_consumer_group_id.json index 4e3665a66c..628c8874db 100644 --- a/tests/translator/output/error_consumer_group_id.json +++ b/tests/translator/output/error_consumer_group_id.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [NotSupportedPullTrigger] is invalid. Event with id [NotSupportedPullTriggerDDBEvent] is invalid. Property ConsumerGroupId not defined for resource of type DynamoDB. Resource with id [NotSupportedPushTriggerSNSEvent] is invalid. property ConsumerGroupId not defined for resource of type SNS" -} \ No newline at end of file +} diff --git a/tests/translator/output/error_cors_credentials_true_with_wildcard_origin.json b/tests/translator/output/error_cors_credentials_true_with_wildcard_origin.json index 63932e749a..6c4395ca31 100644 --- a/tests/translator/output/error_cors_credentials_true_with_wildcard_origin.json +++ b/tests/translator/output/error_cors_credentials_true_with_wildcard_origin.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Unable to add Cors configuration because 'AllowCredentials' can not be true when 'AllowOrigin' is \"'*'\" or not set", "errors": [ { "errorMessage": "Resource with id [ExplicitApi] is invalid. Unable to add Cors configuration because 'AllowCredentials' can not be true when 'AllowOrigin' is '*' or not set" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Unable to add Cors configuration because 'AllowCredentials' can not be true when 'AllowOrigin' is \"'*'\" or not set" + ] } diff --git a/tests/translator/output/error_cors_credentials_true_without_explicit_origin.json b/tests/translator/output/error_cors_credentials_true_without_explicit_origin.json index 63932e749a..6c4395ca31 100644 --- a/tests/translator/output/error_cors_credentials_true_without_explicit_origin.json +++ b/tests/translator/output/error_cors_credentials_true_without_explicit_origin.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Unable to add Cors configuration because 'AllowCredentials' can not be true when 'AllowOrigin' is \"'*'\" or not set", "errors": [ { "errorMessage": "Resource with id [ExplicitApi] is invalid. Unable to add Cors configuration because 'AllowCredentials' can not be true when 'AllowOrigin' is '*' or not set" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Unable to add Cors configuration because 'AllowCredentials' can not be true when 'AllowOrigin' is \"'*'\" or not set" + ] } diff --git a/tests/translator/output/error_cors_on_external_swagger.json b/tests/translator/output/error_cors_on_external_swagger.json index 528129a2b1..c1670cec24 100644 --- a/tests/translator/output/error_cors_on_external_swagger.json +++ b/tests/translator/output/error_cors_on_external_swagger.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Cors works only with inline Swagger specified in 'DefinitionBody' property.", "errors": [ { "errorMessage": "Resource with id [ExplicitApi] is invalid. Cors works only with inline Swagger specified in 'DefinitionBody' property." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ExplicitApi] is invalid. Cors works only with inline Swagger specified in 'DefinitionBody' property." + ] } diff --git a/tests/translator/output/error_default_authorizer_should_be_string_in_api.json b/tests/translator/output/error_default_authorizer_should_be_string_in_api.json index b3394c79be..77b8a53e78 100644 --- a/tests/translator/output/error_default_authorizer_should_be_string_in_api.json +++ b/tests/translator/output/error_default_authorizer_should_be_string_in_api.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. DefaultAuthorizer is not a string." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. DefaultAuthorizer is not a string." +} diff --git a/tests/translator/output/error_depends_on_invalid_types.json b/tests/translator/output/error_depends_on_invalid_types.json index 2a4f1f8864..e215c4b6b5 100644 --- a/tests/translator/output/error_depends_on_invalid_types.json +++ b/tests/translator/output/error_depends_on_invalid_types.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [Function1BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings. Resource with id [Function2BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings. Resource with id [Function3BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings.", "errors": [ { "errorMessage": "Resource with id [Function1BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings. Resource with id [Function2BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings. Resource with id [Function3BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [Function1BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings. Resource with id [Function2BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings. Resource with id [Function3BucketEvent] is invalid. Invalid type for field 'DependsOn'. Expected a string or list of strings." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_event_filtering.json b/tests/translator/output/error_event_filtering.json index fb38fcf76a..bf5a964a93 100644 --- a/tests/translator/output/error_event_filtering.json +++ b/tests/translator/output/error_event_filtering.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [NotSupportedPushEventSNSEvent] is invalid. property FilterCriteria not defined for resource of type SNS Resource with id [WrongFilterName] is invalid. Event with id [DynamoDBStreamEvent] is invalid. FilterCriteria field has a wrong format" -} \ No newline at end of file +} diff --git a/tests/translator/output/error_existing_event_logical_id.json b/tests/translator/output/error_existing_event_logical_id.json index ca678a8964..bed644dc39 100644 --- a/tests/translator/output/error_existing_event_logical_id.json +++ b/tests/translator/output/error_existing_event_logical_id.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource.", "errors": [ { "errorMessage": "Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [IoTRuleFunc] attempts to create a new resource with id [IoTRuleFuncMyIoTRule] and type \"AWS::IoT::TopicRule\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_existing_permission_logical_id.json b/tests/translator/output/error_existing_permission_logical_id.json index c41d0abd0a..d48445d311 100644 --- a/tests/translator/output/error_existing_permission_logical_id.json +++ b/tests/translator/output/error_existing_permission_logical_id.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource.", "errors": [ { "errorMessage": "Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [AlexaSkillFunc] attempts to create a new resource with id [AlexaSkillFuncAlexaSkillEventPermission] and type \"AWS::Lambda::Permission\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_existing_role_logical_id.json b/tests/translator/output/error_existing_role_logical_id.json index b01da10488..56ee6999d3 100644 --- a/tests/translator/output/error_existing_role_logical_id.json +++ b/tests/translator/output/error_existing_role_logical_id.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource.", "errors": [ { "errorMessage": "Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Transforming resource with id [RestApiFunction] attempts to create a new resource with id [RestApiFunctionRole] and type \"AWS::IAM::Role\". A resource with that id already exists within this template. Please use a different id for that resource." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_api_invalid_properties.json b/tests/translator/output/error_function_api_invalid_properties.json index 7208a90478..9850aad2f4 100644 --- a/tests/translator/output/error_function_api_invalid_properties.json +++ b/tests/translator/output/error_function_api_invalid_properties.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [Api] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_fnsub_in_auto_publish_hash.json b/tests/translator/output/error_function_fnsub_in_auto_publish_hash.json index 9d26004b67..9977dd7551 100644 --- a/tests/translator/output/error_function_fnsub_in_auto_publish_hash.json +++ b/tests/translator/output/error_function_fnsub_in_auto_publish_hash.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. AutoPublishCodeSha256 must be a string", "errors": [ { "errorMessage": "[Function] is invalid. AutoPublishCodeSha256 must be a string" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. AutoPublishCodeSha256 must be a string" + ] } diff --git a/tests/translator/output/error_function_invalid_api_event.json b/tests/translator/output/error_function_invalid_api_event.json index 48027216a9..a76e1e7c9c 100644 --- a/tests/translator/output/error_function_invalid_api_event.json +++ b/tests/translator/output/error_function_invalid_api_event.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [FunctionApiInvalidProperties] is invalid. Event with id [ApiEvent] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue. Resource with id [FunctionApiMethodArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Method'. Resource with id [FunctionApiNoMethod] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Method'. Resource with id [FunctionApiNoPath] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Path'. Resource with id [FunctionApiPathArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Path'.", "errors": [ { "errorMessage": "Resource with id [FunctionApiNoMethod] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Path'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [FunctionApiInvalidProperties] is invalid. Event with id [ApiEvent] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue. Resource with id [FunctionApiMethodArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Method'. Resource with id [FunctionApiNoMethod] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Method'. Resource with id [FunctionApiNoPath] is invalid. Event with id [ApiEvent] is invalid. Event is missing key 'Path'. Resource with id [FunctionApiPathArray] is invalid. Event with id [ApiEvent] is invalid. Api Event must have a String specified for 'Path'." + ] } diff --git a/tests/translator/output/error_function_invalid_autopublishalias.json b/tests/translator/output/error_function_invalid_autopublishalias.json index 820df472fe..27fdeaf29b 100644 --- a/tests/translator/output/error_function_invalid_autopublishalias.json +++ b/tests/translator/output/error_function_invalid_autopublishalias.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [InvalidAutoPublishAliasFunction] is invalid. Alias name is required to create an alias", "errors": [ { "errorMessage": "Resource with id [InvalidAutoPublishAliasFunction] is invalid. Alias name is required to create an alias" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [InvalidAutoPublishAliasFunction] is invalid. Alias name is required to create an alias" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_invalid_codeuri.json b/tests/translator/output/error_function_invalid_codeuri.json index ce3df94813..69d2a17470 100644 --- a/tests/translator/output/error_function_invalid_codeuri.json +++ b/tests/translator/output/error_function_invalid_codeuri.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. 'CodeUri' is not a valid S3 Uri of the form \"s3://bucket/key\" with optional versionId query parameter." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter." + ] } diff --git a/tests/translator/output/error_function_invalid_event_api_ref.json b/tests/translator/output/error_function_invalid_event_api_ref.json index b02fdaa75b..d2327116d3 100644 --- a/tests/translator/output/error_function_invalid_event_api_ref.json +++ b/tests/translator/output/error_function_invalid_event_api_ref.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionApiRestApiRefError] is invalid. Event with id [ApiEvent] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template.", "errors": [ { "errorMessage": "Resource with id [FunctionApiRestApiRefError] is invalid. Event with id [ApiEvent] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionApiRestApiRefError] is invalid. Event with id [ApiEvent] is invalid. Api Event's RestApiId must be a string referencing an Api in the same template." + ] } diff --git a/tests/translator/output/error_function_invalid_event_http_api_ref.json b/tests/translator/output/error_function_invalid_event_http_api_ref.json index 466a4bf4fd..37ac0153aa 100644 --- a/tests/translator/output/error_function_invalid_event_http_api_ref.json +++ b/tests/translator/output/error_function_invalid_event_http_api_ref.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionApiHttpApiRefError] is invalid. Event with id [ApiEvent] is invalid. Api Event's ApiId must be a string referencing an Api in the same template.", "errors": [ { "errorMessage": "Resource with id [FunctionApiHttpApiRefError] is invalid. Event with id [ApiEvent] is invalid. Api Event's ApiId must be a string referencing an Api in the same template." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionApiHttpApiRefError] is invalid. Event with id [ApiEvent] is invalid. Api Event's ApiId must be a string referencing an Api in the same template." + ] } diff --git a/tests/translator/output/error_function_invalid_event_type.json b/tests/translator/output/error_function_invalid_event_type.json index d816f28fb3..e8aaf5074d 100644 --- a/tests/translator/output/error_function_invalid_event_type.json +++ b/tests/translator/output/error_function_invalid_event_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [FunctionApiTypeError] is invalid. Event with id [ApiEvent] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: API. Resource with id [FunctionNoEventType] is invalid. Event with id [MissingType] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: None. Resource with id [TestFunction] is invalid. Event with id [FileUploaded] is invalid. 'NoneType' object has no attribute 'get'", "errors": [ { "errorMessage": "Resource with id [FunctionApiTypeError] is invalid. Event with id [ApiEvent] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: API. Resource with id [FunctionNoEventType] is invalid. Event with id [MissingType] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: None." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [FunctionApiTypeError] is invalid. Event with id [ApiEvent] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: API. Resource with id [FunctionNoEventType] is invalid. Event with id [MissingType] is invalid. Resource dict has missing or invalid value for key Type. Event Type is: None. Resource with id [TestFunction] is invalid. Event with id [FileUploaded] is invalid. 'NoneType' object has no attribute 'get'" + ] } diff --git a/tests/translator/output/error_function_invalid_layer.json b/tests/translator/output/error_function_invalid_layer.json index 94d1a11a97..fb3985a1f4 100644 --- a/tests/translator/output/error_function_invalid_layer.json +++ b/tests/translator/output/error_function_invalid_layer.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionWithLayersString] is invalid. Type of property 'Layers' is invalid.", "errors": [ { "errorMessage": "Resource with id [FunctionWithLayersString] is invalid. Type of property 'Layers' is invalid." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionWithLayersString] is invalid. Type of property 'Layers' is invalid." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_invalid_request_parameters.json b/tests/translator/output/error_function_invalid_request_parameters.json index cfc8690061..758c28bc9c 100644 --- a/tests/translator/output/error_function_invalid_request_parameters.json +++ b/tests/translator/output/error_function_invalid_request_parameters.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [InvalidNameDictParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameLocationStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [InvalidNameStringParameterFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Keys must be in the format 'method.request.[querystring|path|header].{value}', e.g 'method.request.header.Authorization'. Resource with id [ParameterInvalidFieldFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Values must be an object, e.g { Required: true, Caching: false } Resource with id [ParameterNotDictOrStringFunction] is invalid. Event with id [GetHtml] is invalid. Invalid value for 'RequestParameters' property. Property must be either a string or an object" -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_invalid_s3_event.json b/tests/translator/output/error_function_invalid_s3_event.json index d762590732..14dde55ea9 100644 --- a/tests/translator/output/error_function_invalid_s3_event.json +++ b/tests/translator/output/error_function_invalid_s3_event.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionInvalidS3EventS3Event] is invalid. Type of property 'Events' is invalid.", "errors": [ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionInvalidS3EventS3Event] is invalid. Type of property 'Events' is invalid." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [FunctionInvalidS3EventS3Event] is invalid. Type of property 'Events' is invalid." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_no_codeuri.json b/tests/translator/output/error_function_no_codeuri.json index 2de25914fe..30b33b6fb9 100644 --- a/tests/translator/output/error_function_no_codeuri.json +++ b/tests/translator/output/error_function_no_codeuri.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Only one of 'InlineCode' or 'CodeUri' can be set.", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. Either 'InlineCode' or 'CodeUri' must be set." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Only one of 'InlineCode' or 'CodeUri' can be set." + ] } diff --git a/tests/translator/output/error_function_no_handler.json b/tests/translator/output/error_function_no_handler.json index 8bd371adec..caeec6dfa5 100644 --- a/tests/translator/output/error_function_no_handler.json +++ b/tests/translator/output/error_function_no_handler.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Runtime and Handler needs to be present when PackageType is of type `Zip`", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. Runtime and Handler needs to be present when PackageType is of type `Zip`" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Runtime and Handler needs to be present when PackageType is of type `Zip`" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_no_imageuri.json b/tests/translator/output/error_function_no_imageuri.json index b07123c0ab..e7270d0ba5 100644 --- a/tests/translator/output/error_function_no_imageuri.json +++ b/tests/translator/output/error_function_no_imageuri.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. 'ImageUri' must be set.", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. 'ImageUri' must be set." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. 'ImageUri' must be set." + ] } diff --git a/tests/translator/output/error_function_no_runtime.json b/tests/translator/output/error_function_no_runtime.json index ed1b9f21bb..caeec6dfa5 100644 --- a/tests/translator/output/error_function_no_runtime.json +++ b/tests/translator/output/error_function_no_runtime.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Runtime and Handler needs to be present when PackageType is of type `Zip`", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. Runtime and Handler needs to be present when PackageType is of type `Zip`" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Runtime and Handler needs to be present when PackageType is of type `Zip`" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_policy_template_invalid_value.json b/tests/translator/output/error_function_policy_template_invalid_value.json index e21372d5f9..ec42bed915 100644 --- a/tests/translator/output/error_function_policy_template_invalid_value.json +++ b/tests/translator/output/error_function_policy_template_invalid_value.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Must specify valid parameter values for policy template 'LambdaInvokePolicy'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Must specify valid parameter values for policy template 'LambdaInvokePolicy'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Must specify valid parameter values for policy template 'LambdaInvokePolicy'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_policy_template_with_missing_parameter.json b/tests/translator/output/error_function_policy_template_with_missing_parameter.json index 0642a0591d..e0187010e5 100644 --- a/tests/translator/output/error_function_policy_template_with_missing_parameter.json +++ b/tests/translator/output/error_function_policy_template_with_missing_parameter.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Following required parameters of template 'LambdaInvokePolicy' don't have values: ['FunctionName']", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Following required parameters of template 'LambdaInvokePolicy' don't have values: ['FunctionName']" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Following required parameters of template 'LambdaInvokePolicy' don't have values: ['FunctionName']" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_api_key_false.json b/tests/translator/output/error_function_with_api_key_false.json index c44e9012b9..ff43b77618 100644 --- a/tests/translator/output/error_function_with_api_key_false.json +++ b/tests/translator/output/error_function_with_api_key_false.json @@ -1,8 +1,8 @@ - { +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunctionWithApiKeyRequired] is invalid. Event with id [MyApiWithApiKeyRequired] is invalid. Unable to set ApiKeyRequired [False] on API method [get] for path [/ApiKeyRequiredTrue] because the related API does not specify any ApiKeyRequired.", "errors": [ { "errorMessage": "Resource with id [MyFunctionWithApiKeyRequired] is invalid. Event with id [MyApiWithApiKeyRequired] is invalid. Unable to set ApiKeyRequired [False] on API method [get] for path [/ApiKeyRequiredTrue] because the related API does not specify any ApiKeyRequired." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunctionWithApiKeyRequired] is invalid. Event with id [MyApiWithApiKeyRequired] is invalid. Unable to set ApiKeyRequired [False] on API method [get] for path [/ApiKeyRequiredTrue] because the related API does not specify any ApiKeyRequired." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_cwe_both_dlq_property_provided.json b/tests/translator/output/error_function_with_cwe_both_dlq_property_provided.json index 541990f400..9abc3e868d 100644 --- a/tests/translator/output/error_function_with_cwe_both_dlq_property_provided.json +++ b/tests/translator/output/error_function_with_cwe_both_dlq_property_provided.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TriggeredFunction] is invalid. Event with id [TriggeredFunctionOnTerminate] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TriggeredFunction] is invalid. Event with id [TriggeredFunctionOnTerminate] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" +} diff --git a/tests/translator/output/error_function_with_cwe_invalid_dlq_type.json b/tests/translator/output/error_function_with_cwe_invalid_dlq_type.json index ded9379e67..e73edc94ee 100644 --- a/tests/translator/output/error_function_with_cwe_invalid_dlq_type.json +++ b/tests/translator/output/error_function_with_cwe_invalid_dlq_type.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TriggeredFunction] is invalid. Event with id [TriggeredFunctionOnTerminate] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TriggeredFunction] is invalid. Event with id [TriggeredFunctionOnTerminate] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" +} diff --git a/tests/translator/output/error_function_with_cwe_missing_dlq_property.json b/tests/translator/output/error_function_with_cwe_missing_dlq_property.json index edf6a7fd79..9ff14dc619 100644 --- a/tests/translator/output/error_function_with_cwe_missing_dlq_property.json +++ b/tests/translator/output/error_function_with_cwe_missing_dlq_property.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TriggeredFunction] is invalid. Event with id [TriggeredFunctionOnTerminate] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TriggeredFunction] is invalid. Event with id [TriggeredFunctionOnTerminate] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" +} diff --git a/tests/translator/output/error_function_with_deployment_preference_invalid_alarms.json b/tests/translator/output/error_function_with_deployment_preference_invalid_alarms.json index ee4e8d6174..c96b8c9b74 100644 --- a/tests/translator/output/error_function_with_deployment_preference_invalid_alarms.json +++ b/tests/translator/output/error_function_with_deployment_preference_invalid_alarms.json @@ -1,11 +1,11 @@ { - "errors": [ - { - "errorMessage": "Resource with id [MinimalFunction] is invalid. Alarms must be a list" - }, - { - "errorMessage": "Resource with id [MinimalFunction] is invalid. Alarms must be a list" - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MinimalFunction] is invalid. Alarms must be a list Resource with id [MinimalFunction] is invalid. Alarms must be a list" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MinimalFunction] is invalid. Alarms must be a list Resource with id [MinimalFunction] is invalid. Alarms must be a list", + "errors": [ + { + "errorMessage": "Resource with id [MinimalFunction] is invalid. Alarms must be a list" + }, + { + "errorMessage": "Resource with id [MinimalFunction] is invalid. Alarms must be a list" + } + ] +} diff --git a/tests/translator/output/error_function_with_deployment_preference_missing_alias.json b/tests/translator/output/error_function_with_deployment_preference_missing_alias.json index 0c9f4ede35..ee76c819eb 100644 --- a/tests/translator/output/error_function_with_deployment_preference_missing_alias.json +++ b/tests/translator/output/error_function_with_deployment_preference_missing_alias.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. 'DeploymentPreference' requires AutoPublishAlias property to be specified.", "errors": [ { "errorMessage": "Resource with id [MinimalFunction] is invalid. 'DeploymentPreference' requires AutoPublishAlias property to be specified." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. 'DeploymentPreference' requires AutoPublishAlias property to be specified." + ] } diff --git a/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json b/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json index 931b1c7d20..6373c0b14e 100644 --- a/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json +++ b/tests/translator/output/error_function_with_deployment_preference_passthrough_condition_with_invalid_values.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [InvalidType] is invalid. Invalid value for property PassthroughCondition. Resource with id [UnsupportedIntrinsic] is invalid. Unsupported intrinsic: the only intrinsic functions supported for property PassthroughCondition are FindInMap and parameter Refs." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [InvalidType] is invalid. Invalid value for property PassthroughCondition. Resource with id [UnsupportedIntrinsic] is invalid. Unsupported intrinsic: the only intrinsic functions supported for property PassthroughCondition are FindInMap and parameter Refs." +} diff --git a/tests/translator/output/error_function_with_event_bridge_rule_dlq_intrinsic_function.json b/tests/translator/output/error_function_with_event_bridge_rule_dlq_intrinsic_function.json index 8d3e859272..774b139860 100644 --- a/tests/translator/output/error_function_with_event_bridge_rule_dlq_intrinsic_function.json +++ b/tests/translator/output/error_function_with_event_bridge_rule_dlq_intrinsic_function.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [testLambdaFn] is invalid. Event with id [testLambdaFnTestEventBridgeRule] is invalid. QueueLogicalId must be a string", "errors": [ { "errorMessage": "Event with id [testLambdaFnTestEventBridgeRule] is invalid. QueueLogicalId must be a string" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [testLambdaFn] is invalid. Event with id [testLambdaFnTestEventBridgeRule] is invalid. QueueLogicalId must be a string" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_event_dest_invalid.json b/tests/translator/output/error_function_with_event_dest_invalid.json index eaebae2f4b..21424a5c59 100644 --- a/tests/translator/output/error_function_with_event_dest_invalid.json +++ b/tests/translator/output/error_function_with_event_dest_invalid.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyTestFunction] is invalid. Destination is required if Type is not ['SQS', 'SNS']", "errors": [ { "errorMessage": "Resource with id [MyTestFunction] is invalid. Destination is required if Type is not ['SQS', 'SNS']" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyTestFunction] is invalid. Destination is required if Type is not ['SQS', 'SNS']" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_event_dest_type.json b/tests/translator/output/error_function_with_event_dest_type.json index 7388abec42..82c4762d5f 100644 --- a/tests/translator/output/error_function_with_event_dest_type.json +++ b/tests/translator/output/error_function_with_event_dest_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyTestFunction] is invalid. 'Type: blah' must be one of ['SQS', 'SNS', 'EventBridge', 'Lambda']", "errors": [ { "errorMessage": "Resource with id [MyTestFunction] is invalid. 'Type: blah' must be one of ['SQS', 'SNS', 'EventBridge', 'Lambda']" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyTestFunction] is invalid. 'Type: blah' must be one of ['SQS', 'SNS', 'EventBridge', 'Lambda']" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter.json b/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter.json index 749880b677..995e2d1d88 100644 --- a/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter.json +++ b/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. AllowOrigin is not a valid property for configuring Cors." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter_data_type.json b/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter_data_type.json index 4f02f1bc4e..8d4ec696da 100644 --- a/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter_data_type.json +++ b/tests/translator/output/error_function_with_function_url_config_with_invalid_cors_parameter_data_type.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. MaxAge must be of type int." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_function_url_config_with_no_authorization_type.json b/tests/translator/output/error_function_with_function_url_config_with_no_authorization_type.json index 7d67b711e1..4ad36f8f60 100644 --- a/tests/translator/output/error_function_with_function_url_config_with_no_authorization_type.json +++ b/tests/translator/output/error_function_with_function_url_config_with_no_authorization_type.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. AuthType is required to configure function property `FunctionUrlConfig`. Please provide either AWS_IAM or NONE." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_invalid_condition_name.json b/tests/translator/output/error_function_with_invalid_condition_name.json index 628769ae9a..3e2da2acf3 100644 --- a/tests/translator/output/error_function_with_invalid_condition_name.json +++ b/tests/translator/output/error_function_with_invalid_condition_name.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Every Condition member must be a string.", "errors": [ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Every Condition member must be a string." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Every Condition member must be a string." + ] } diff --git a/tests/translator/output/error_function_with_invalid_deployment_preference_hook_property.json b/tests/translator/output/error_function_with_invalid_deployment_preference_hook_property.json index a19a9fb778..251a19e5e2 100644 --- a/tests/translator/output/error_function_with_invalid_deployment_preference_hook_property.json +++ b/tests/translator/output/error_function_with_invalid_deployment_preference_hook_property.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. 'Hooks' property of 'DeploymentPreference' must be a dictionary", "errors": [ { "errorMessage": "Resource with id [MinimalFunction] is invalid. 'Hooks' property of 'DeploymentPreference' must be a dictionary" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. 'Hooks' property of 'DeploymentPreference' must be a dictionary" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_invalid_dlq_property_type.json b/tests/translator/output/error_function_with_invalid_dlq_property_type.json index a901eca0d7..f67b294bb2 100644 --- a/tests/translator/output/error_function_with_invalid_dlq_property_type.json +++ b/tests/translator/output/error_function_with_invalid_dlq_property_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MySqsDlqLambdaFunction] is invalid. 'DeadLetterQueue' property 'Type' should be of type str.", "errors": [ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MySqsDlqLambdaFunction] is invalid. 'DeadLetterQueue' property 'Type' should be of type str." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MySqsDlqLambdaFunction] is invalid. 'DeadLetterQueue' property 'Type' should be of type str." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_invalid_event_bridge_rule.json b/tests/translator/output/error_function_with_invalid_event_bridge_rule.json index d4720681ca..3da966b588 100644 --- a/tests/translator/output/error_function_with_invalid_event_bridge_rule.json +++ b/tests/translator/output/error_function_with_invalid_event_bridge_rule.json @@ -1 +1,3 @@ -{"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TestFunction] is invalid. Event with id [TestEventBridgeRule] is invalid. State and Enabled Properties cannot both be specified."} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TestFunction] is invalid. Event with id [TestEventBridgeRule] is invalid. State and Enabled Properties cannot both be specified." +} diff --git a/tests/translator/output/error_function_with_invalid_kms_type_for_self_managed_kafka.json b/tests/translator/output/error_function_with_invalid_kms_type_for_self_managed_kafka.json index 67bfd9cf1e..8523620930 100644 --- a/tests/translator/output/error_function_with_invalid_kms_type_for_self_managed_kafka.json +++ b/tests/translator/output/error_function_with_invalid_kms_type_for_self_managed_kafka.json @@ -5,4 +5,4 @@ "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Provided SecretsManagerKmsKeyId should be of type str." } ] -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_invalid_policy_statement.json b/tests/translator/output/error_function_with_invalid_policy_statement.json index b8e7506011..7f43c1586d 100644 --- a/tests/translator/output/error_function_with_invalid_policy_statement.json +++ b/tests/translator/output/error_function_with_invalid_policy_statement.json @@ -1,4 +1,8 @@ { - "errors": [{"errorMessage": "Resource with id [UnknownTemplate] is invalid. Policy at index 1 in the 'Policies' property is not valid"}], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [UnknownTemplate] is invalid. Policy at index 1 in the 'Policies' property is not valid" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [UnknownTemplate] is invalid. Policy at index 1 in the 'Policies' property is not valid", + "errors": [ + { + "errorMessage": "Resource with id [UnknownTemplate] is invalid. Policy at index 1 in the 'Policies' property is not valid" + } + ] +} diff --git a/tests/translator/output/error_function_with_invalid_schedule_event.json b/tests/translator/output/error_function_with_invalid_schedule_event.json index 8311582e43..c46ce7a457 100644 --- a/tests/translator/output/error_function_with_invalid_schedule_event.json +++ b/tests/translator/output/error_function_with_invalid_schedule_event.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified." - } \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified.", + "errors": [ + { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified." + } + ] +} diff --git a/tests/translator/output/error_function_with_invalid_stream_eventsource_dest_type.json b/tests/translator/output/error_function_with_invalid_stream_eventsource_dest_type.json index dc4f300bdf..f52c232d90 100644 --- a/tests/translator/output/error_function_with_invalid_stream_eventsource_dest_type.json +++ b/tests/translator/output/error_function_with_invalid_stream_eventsource_dest_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. The only valid values for 'Type' are 'SQS' and 'SNS'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_method_auth_and_no_api_auth.json b/tests/translator/output/error_function_with_method_auth_and_no_api_auth.json index db69ac7d04..5e02eb6cb6 100644 --- a/tests/translator/output/error_function_with_method_auth_and_no_api_auth.json +++ b/tests/translator/output/error_function_with_method_auth_and_no_api_auth.json @@ -1,4 +1,8 @@ { - "errors": [{"errorMessage": "Resource with id [HelloWorldFunction] is invalid. Event with id [HttpGetUserGroupIdUserId] is invalid. Unable to set Authorizer on API method [get] for path [/users/{groupId}/{userId}] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified."}], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HelloWorldFunction] is invalid. Event with id [HttpGetUserGroupIdUserId] is invalid. Unable to set Authorizer on API method [get] for path [/users/{groupId}/{userId}] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HelloWorldFunction] is invalid. Event with id [HttpGetUserGroupIdUserId] is invalid. Unable to set Authorizer on API method [get] for path [/users/{groupId}/{userId}] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified.", + "errors": [ + { + "errorMessage": "Resource with id [HelloWorldFunction] is invalid. Event with id [HttpGetUserGroupIdUserId] is invalid. Unable to set Authorizer on API method [get] for path [/users/{groupId}/{userId}] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified." + } + ] +} diff --git a/tests/translator/output/error_function_with_missing_on_failure_in_stream_event_destination_config.json b/tests/translator/output/error_function_with_missing_on_failure_in_stream_event_destination_config.json index dcc5d33fb1..a60f6883d3 100644 --- a/tests/translator/output/error_function_with_missing_on_failure_in_stream_event_destination_config.json +++ b/tests/translator/output/error_function_with_missing_on_failure_in_stream_event_destination_config.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'", "errors": [ { "errorMessage": "Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyFunction] is invalid. Event with id [MyFunctionStreamEvent] is invalid. 'OnFailure' is a required field for 'DestinationConfig'" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_mq_kms_invalid_type.json b/tests/translator/output/error_function_with_mq_kms_invalid_type.json index 268fb6354d..3d3e4af3f8 100644 --- a/tests/translator/output/error_function_with_mq_kms_invalid_type.json +++ b/tests/translator/output/error_function_with_mq_kms_invalid_type.json @@ -5,4 +5,4 @@ "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Provided SecretsManagerKmsKeyId should be of type str." } ] -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_multiple_architectures.json b/tests/translator/output/error_function_with_multiple_architectures.json index d266cb94af..df0a11d849 100644 --- a/tests/translator/output/error_function_with_multiple_architectures.json +++ b/tests/translator/output/error_function_with_multiple_architectures.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TestFunc] is invalid. Architectures needs to be a list with one string, either `x86_64` or `arm64`." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_no_alias_provisioned_concurrency.json b/tests/translator/output/error_function_with_no_alias_provisioned_concurrency.json index 1e5d1559e9..b8bfdc0f85 100644 --- a/tests/translator/output/error_function_with_no_alias_provisioned_concurrency.json +++ b/tests/translator/output/error_function_with_no_alias_provisioned_concurrency.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. To set ProvisionedConcurrencyConfig AutoPublishALias must be defined on the function", "errors": [ { "errorMessage": "Resource with id [MinimalFunction] is invalid. To set ProvisionedConcurrencyConfig AutoPublishALias must be defined on the function" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MinimalFunction] is invalid. To set ProvisionedConcurrencyConfig AutoPublishALias must be defined on the function" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_schedue_dlq_intrinsic_function.json b/tests/translator/output/error_function_with_schedue_dlq_intrinsic_function.json index d7d5a70fa8..84e30a2f40 100644 --- a/tests/translator/output/error_function_with_schedue_dlq_intrinsic_function.json +++ b/tests/translator/output/error_function_with_schedue_dlq_intrinsic_function.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [testLambdaFn] is invalid. Event with id [testLambdaFnSchedule] is invalid. QueueLogicalId must be a string", "errors": [ { "errorMessage": "Event with id [testLambdaFnSchedule] is invalid. QueueLogicalId must be a string" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [testLambdaFn] is invalid. Event with id [testLambdaFnSchedule] is invalid. QueueLogicalId must be a string" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_function_with_schedule_both_dlq_property_provided.json b/tests/translator/output/error_function_with_schedule_both_dlq_property_provided.json index 9a90e5cf99..7d5047ea95 100644 --- a/tests/translator/output/error_function_with_schedule_both_dlq_property_provided.json +++ b/tests/translator/output/error_function_with_schedule_both_dlq_property_provided.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [ScheduledFunctionSchedule] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [ScheduledFunctionSchedule] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" +} diff --git a/tests/translator/output/error_function_with_schedule_invalid_dlq_type.json b/tests/translator/output/error_function_with_schedule_invalid_dlq_type.json index d779e7ea0b..f6f334da17 100644 --- a/tests/translator/output/error_function_with_schedule_invalid_dlq_type.json +++ b/tests/translator/output/error_function_with_schedule_invalid_dlq_type.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [ScheduledFunctionSchedule] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [ScheduledFunctionSchedule] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" +} diff --git a/tests/translator/output/error_function_with_schedule_missing_dlq_property.json b/tests/translator/output/error_function_with_schedule_missing_dlq_property.json index bb004d8d87..d653850d4c 100644 --- a/tests/translator/output/error_function_with_schedule_missing_dlq_property.json +++ b/tests/translator/output/error_function_with_schedule_missing_dlq_property.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [ScheduledFunctionSchedule] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ScheduledFunction] is invalid. Event with id [ScheduledFunctionSchedule] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" +} diff --git a/tests/translator/output/error_function_with_unknown_architectures.json b/tests/translator/output/error_function_with_unknown_architectures.json index 56ca04788c..b88fb1614a 100644 --- a/tests/translator/output/error_function_with_unknown_architectures.json +++ b/tests/translator/output/error_function_with_unknown_architectures.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [TestFunc] is invalid. Architectures needs to be a list with one string, either `x86_64` or `arm64`. Resource with id [TestFunc2] is invalid. Type of property 'Architectures' is invalid." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_function_with_unknown_policy_template.json b/tests/translator/output/error_function_with_unknown_policy_template.json index 6853f2e2cc..5ba89e3526 100644 --- a/tests/translator/output/error_function_with_unknown_policy_template.json +++ b/tests/translator/output/error_function_with_unknown_policy_template.json @@ -1,4 +1,8 @@ { - "errors": [{"errorMessage": "Resource with id [UnknownTemplate] is invalid. Policy at index 2 in the 'Policies' property is not valid"}], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [UnknownTemplate] is invalid. Policy at index 2 in the 'Policies' property is not valid" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [UnknownTemplate] is invalid. Policy at index 2 in the 'Policies' property is not valid", + "errors": [ + { + "errorMessage": "Resource with id [UnknownTemplate] is invalid. Policy at index 2 in the 'Policies' property is not valid" + } + ] +} diff --git a/tests/translator/output/error_gateway_response_invalid_type_int.json b/tests/translator/output/error_gateway_response_invalid_type_int.json index d324c4e87c..6a22a82dcb 100644 --- a/tests/translator/output/error_gateway_response_invalid_type_int.json +++ b/tests/translator/output/error_gateway_response_invalid_type_int.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiResource] is invalid. Invalid property type 'int' for GatewayResponses. Expected an object of type 'GatewayResponse'.", "errors": [ { "errorMessage": "Resource with id [ApiResource] is invalid. Invalid property type 'int' for GatewayResponses. Expected an object of type 'GatewayResponse'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiResource] is invalid. Invalid property type 'int' for GatewayResponses. Expected an object of type 'GatewayResponse'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_gateway_response_invalid_type_intrinsic.json b/tests/translator/output/error_gateway_response_invalid_type_intrinsic.json index e83ff62d68..b3ee6a8a09 100644 --- a/tests/translator/output/error_gateway_response_invalid_type_intrinsic.json +++ b/tests/translator/output/error_gateway_response_invalid_type_intrinsic.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiResource] is invalid. Unable to set GatewayResponses attribute because intrinsic functions are not supported for this field.", "errors": [ { "errorMessage": "Resource with id [ApiResource] is invalid. Unable to set GatewayResponses attribute because intrinsic functions are not supported for this field." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiResource] is invalid. Unable to set GatewayResponses attribute because intrinsic functions are not supported for this field." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_globals_api_with_stage_name.json b/tests/translator/output/error_globals_api_with_stage_name.json index 7faf2ba6b9..6bb994ff42 100644 --- a/tests/translator/output/error_globals_api_with_stage_name.json +++ b/tests/translator/output/error_globals_api_with_stage_name.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Auth', 'Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'MinimumCompressionSize', 'Cors', 'GatewayResponses', 'AccessLogSetting', 'CanarySetting', 'TracingEnabled', 'OpenApiVersion', 'Domain']", "errors": [ { "errorMessage": "'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Auth', 'Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'Cors', 'GatewayResponses', 'AccessLogSetting', 'CanarySetting', 'OpenApiVersion', 'Domain']" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'StageName' is not a supported property of 'Api'. Must be one of the following values - ['Auth', 'Name', 'DefinitionUri', 'CacheClusterEnabled', 'CacheClusterSize', 'Variables', 'EndpointConfiguration', 'MethodSettings', 'BinaryMediaTypes', 'MinimumCompressionSize', 'Cors', 'GatewayResponses', 'AccessLogSetting', 'CanarySetting', 'TracingEnabled', 'OpenApiVersion', 'Domain']" + ] } diff --git a/tests/translator/output/error_globals_is_not_dict.json b/tests/translator/output/error_globals_is_not_dict.json index e67c900fe6..263bfb20aa 100644 --- a/tests/translator/output/error_globals_is_not_dict.json +++ b/tests/translator/output/error_globals_is_not_dict.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "'Globals' section is invalid. It must be a non-empty dictionary" - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. It must be a non-empty dictionary" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. It must be a non-empty dictionary", + "errors": [ + { + "errorMessage": "'Globals' section is invalid. It must be a non-empty dictionary" + } + ] +} diff --git a/tests/translator/output/error_globals_unsupported_property.json b/tests/translator/output/error_globals_unsupported_property.json index fc563d5faa..cf17dda1b5 100644 --- a/tests/translator/output/error_globals_unsupported_property.json +++ b/tests/translator/output/error_globals_unsupported_property.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'SomeKey' is not a supported property of 'Function'. Must be one of the following values - ['Handler', 'Runtime', 'CodeUri', 'DeadLetterQueue', 'Description', 'MemorySize', 'Timeout', 'VpcConfig', 'Environment', 'Tags', 'Tracing', 'KmsKeyArn', 'AutoPublishAlias', 'Layers', 'DeploymentPreference', 'PermissionsBoundary', 'ReservedConcurrentExecutions', 'ProvisionedConcurrencyConfig', 'AssumeRolePolicyDocument', 'EventInvokeConfig', 'FileSystemConfigs', 'CodeSigningConfigArn', 'Architectures', 'EphemeralStorage', 'FunctionUrlConfig']", "errors": [ { "errorMessage": "'Globals' section is invalid. 'SomeKey' is not a supported property of 'Function'. Must be one of the following values - ['Handler', 'Runtime', 'CodeUri', 'DeadLetterQueue', 'Description', 'MemorySize', 'Timeout', 'VpcConfig', 'Environment', 'Tags', 'Tracing', 'KmsKeyArn', 'AutoPublishAlias', 'Layers', 'DeploymentPreference', 'PermissionsBoundary', 'ReservedConcurrentExecutions', 'ProvisionedConcurrencyConfig', 'EventInvokeConfig', 'FileSystemConfigs', 'CodeSigningConfigArn', 'Architectures', 'FunctionUrlConfig']" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'SomeKey' is not a supported property of 'Function'. Must be one of the following values - ['Handler', 'Runtime', 'CodeUri', 'DeadLetterQueue', 'Description', 'MemorySize', 'Timeout', 'VpcConfig', 'Environment', 'Tags', 'Tracing', 'KmsKeyArn', 'AutoPublishAlias', 'Layers', 'DeploymentPreference', 'PermissionsBoundary', 'ReservedConcurrentExecutions', 'ProvisionedConcurrencyConfig', 'AssumeRolePolicyDocument', 'EventInvokeConfig', 'FileSystemConfigs', 'CodeSigningConfigArn', 'Architectures', 'EphemeralStorage', 'FunctionUrlConfig']" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_globals_unsupported_type.json b/tests/translator/output/error_globals_unsupported_type.json index c1898fe6a8..214796cb7b 100644 --- a/tests/translator/output/error_globals_unsupported_type.json +++ b/tests/translator/output/error_globals_unsupported_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'NewType' is not supported. Must be one of the following values - ['Api', 'Function', 'HttpApi', 'SimpleTable']", "errors": [ { "errorMessage": "'Globals' section is invalid. 'NewType' is not supported. Must be one of the following values - ['Api', 'Function', 'HttpApi', 'SimpleTable']" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. 'Globals' section is invalid. 'NewType' is not supported. Must be one of the following values - ['Api', 'Function', 'HttpApi', 'SimpleTable']" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_def_body_uri.json b/tests/translator/output/error_http_api_def_body_uri.json index dd455feb78..df2151e311 100644 --- a/tests/translator/output/error_http_api_def_body_uri.json +++ b/tests/translator/output/error_http_api_def_body_uri.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both.", "errors": [ { "errorMessage": "Resource with id [MyApi] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Specify either 'DefinitionUri' or 'DefinitionBody' property and not both." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_event_invalid_api.json b/tests/translator/output/error_http_api_event_invalid_api.json index acbe70f0ee..a7ac1365e6 100644 --- a/tests/translator/output/error_http_api_event_invalid_api.json +++ b/tests/translator/output/error_http_api_event_invalid_api.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Api] is invalid. ApiId must be a valid reference to an 'AWS::Serverless::HttpApi' resource in same template.", "errors": [ { "errorMessage": "Resource with id [HttpApiFunction] is invalid. Event with id [Api] is invalid. ApiId must be a valid reference to an 'AWS::Serverless::HttpApi' resource in same template." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Api] is invalid. ApiId must be a valid reference to an 'AWS::Serverless::HttpApi' resource in same template." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_event_multiple_same_path.json b/tests/translator/output/error_http_api_event_multiple_same_path.json index d3130be01e..458f021fe1 100644 --- a/tests/translator/output/error_http_api_event_multiple_same_path.json +++ b/tests/translator/output/error_http_api_event_multiple_same_path.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction2] is invalid. Event with id [Api2] is invalid. API method 'x-amazon-apigateway-any-method' defined multiple times for path '$default'.", "errors": [ { "errorMessage": "Resource with id [HttpApiFunction2] is invalid. Event with id [Api2] is invalid. API method 'x-amazon-apigateway-any-method' defined multiple times for path '$default'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction2] is invalid. Event with id [Api2] is invalid. API method 'x-amazon-apigateway-any-method' defined multiple times for path '$default'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_invalid_auth.json b/tests/translator/output/error_http_api_invalid_auth.json index 45b77428a2..f7a435bbd3 100644 --- a/tests/translator/output/error_http_api_invalid_auth.json +++ b/tests/translator/output/error_http_api_invalid_auth.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [Function] is invalid. Event with id [Api] is invalid. Unable to set Authorizer [myAuth] on API method [x-amazon-apigateway-any-method] for path [$default] because the related API does not define any Authorizers. Resource with id [Function2] is invalid. Event with id [Api2] is invalid. Unable to set Authorizer [myAuth] on API method [x-amazon-apigateway-any-method] for path [$default] because it wasn't defined in the API's Authorizers. Resource with id [Function3] is invalid. Event with id [Api3] is invalid. Unable to set Authorizer on API method [x-amazon-apigateway-any-method] for path [$default] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified. Resource with id [Function4] is invalid. Event with id [Api4] is invalid. Unable to set Authorizer on API method [x-amazon-apigateway-any-method] for path [$default] because 'AuthorizationScopes' must be a list of strings. Resource with id [MyApi5] is invalid. 'OpenIdConnectUrl' is no longer a supported property for authorizer 'OIDC'. Please refer to the AWS SAM documentation. Resource with id [NonStringAuthFunction] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [{'Ref': 'MyAuth'}] on API method [get] for path [/]. The method authorizer must be a string with a corresponding dict entry in the api authorizer.", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. Event with id [Api] is invalid. Unable to set Authorizer [myAuth] on API method [x-amazon-apigateway-any-method] for path [$default] because the related API does not define any Authorizers. Resource with id [Function2] is invalid. Event with id [Api2] is invalid. Unable to set Authorizer [myAuth] on API method [x-amazon-apigateway-any-method] for path [$default] because it wasn't defined in the API's Authorizers. Resource with id [Function3] is invalid. Event with id [Api3] is invalid. Unable to set Authorizer on API method [x-amazon-apigateway-any-method] for path [$default] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified. Resource with id [Function4] is invalid. Event with id [Api4] is invalid. Unable to set Authorizer on API method [x-amazon-apigateway-any-method] for path [$default] because 'AuthorizationScopes' must be a list of strings." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 6. Resource with id [Function] is invalid. Event with id [Api] is invalid. Unable to set Authorizer [myAuth] on API method [x-amazon-apigateway-any-method] for path [$default] because the related API does not define any Authorizers. Resource with id [Function2] is invalid. Event with id [Api2] is invalid. Unable to set Authorizer [myAuth] on API method [x-amazon-apigateway-any-method] for path [$default] because it wasn't defined in the API's Authorizers. Resource with id [Function3] is invalid. Event with id [Api3] is invalid. Unable to set Authorizer on API method [x-amazon-apigateway-any-method] for path [$default] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified. Resource with id [Function4] is invalid. Event with id [Api4] is invalid. Unable to set Authorizer on API method [x-amazon-apigateway-any-method] for path [$default] because 'AuthorizationScopes' must be a list of strings. Resource with id [MyApi5] is invalid. 'OpenIdConnectUrl' is no longer a supported property for authorizer 'OIDC'. Please refer to the AWS SAM documentation. Resource with id [NonStringAuthFunction] is invalid. Event with id [GetRoot] is invalid. Unable to set Authorizer [{'Ref': 'MyAuth'}] on API method [get] for path [/]. The method authorizer must be a string with a corresponding dict entry in the api authorizer." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_invalid_basepath_type.json b/tests/translator/output/error_http_api_invalid_basepath_type.json index dc396ca3dd..d6d40affc5 100644 --- a/tests/translator/output/error_http_api_invalid_basepath_type.json +++ b/tests/translator/output/error_http_api_invalid_basepath_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApi] is invalid. Basepath must be a string.", "errors": [ { "errorMessage": "Resource with id [HttpApi] is invalid. Basepath must be a string." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApi] is invalid. Basepath must be a string." + ] } diff --git a/tests/translator/output/error_http_api_invalid_disable_execute_api_endpoint.json b/tests/translator/output/error_http_api_invalid_disable_execute_api_endpoint.json index 2986706dcb..3945ad2121 100644 --- a/tests/translator/output/error_http_api_invalid_disable_execute_api_endpoint.json +++ b/tests/translator/output/error_http_api_invalid_disable_execute_api_endpoint.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Type of property 'DisableExecuteApiEndpoint' is invalid.", "errors": [ { "errorMessage": "Resource with id [MyApi] is invalid. Type of property 'DisableExecuteApiEndpoint' is invalid." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Type of property 'DisableExecuteApiEndpoint' is invalid." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_invalid_event_authorizer_type.json b/tests/translator/output/error_http_api_invalid_event_authorizer_type.json index 2bce26ea7e..a013731ee8 100644 --- a/tests/translator/output/error_http_api_invalid_event_authorizer_type.json +++ b/tests/translator/output/error_http_api_invalid_event_authorizer_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AuthorizedApi] is invalid. Authorizers must be a dictionary. Resource with id [SignInFunction] is invalid. Event with id [MainFuncPostV1] is invalid. Unable to set Authorizer [['CognitoAuthorizer']] on API method [post] for path [/v1/signin]. The method authorizer must be a string with a corresponding dict entry in the api authorizer.", "errors": [ { "errorMessage": "Resource with id [AuthorizedApi] is invalid. Authorizers must be a dictionary. Resource with id [SignInFunction] is invalid. Event with id [MainFuncPostV1] is invalid. Unable to set Authorizer [['CognitoAuthorizer']] on API method [post] for path [/v1/signin]. The method authorizer must be a string with a corresponding dict entry in the api authorizer." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AuthorizedApi] is invalid. Authorizers must be a dictionary. Resource with id [SignInFunction] is invalid. Event with id [MainFuncPostV1] is invalid. Unable to set Authorizer [['CognitoAuthorizer']] on API method [post] for path [/v1/signin]. The method authorizer must be a string with a corresponding dict entry in the api authorizer." + ] } diff --git a/tests/translator/output/error_http_api_invalid_lambda_auth.json b/tests/translator/output/error_http_api_invalid_lambda_auth.json index 298d917387..337028dffb 100644 --- a/tests/translator/output/error_http_api_invalid_lambda_auth.json +++ b/tests/translator/output/error_http_api_invalid_lambda_auth.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi1] is invalid. LambdaAuth Lambda Authorizer must define 'AuthorizerPayloadFormatVersion'. Resource with id [MyApi2] is invalid. LambdaAuth Lambda Authorizer must define 'FunctionArn'.", "errors": [ { "errorMessage": "Resource with id [MyApi1] is invalid. LambdaAuth Lambda Authorizer must define 'AuthorizerPayloadFormatVersion'. Resource with id [MyApi2] is invalid. LambdaAuth Lambda Authorizer must define 'FunctionArn'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [MyApi1] is invalid. LambdaAuth Lambda Authorizer must define 'AuthorizerPayloadFormatVersion'. Resource with id [MyApi2] is invalid. LambdaAuth Lambda Authorizer must define 'FunctionArn'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_invalid_openapi.json b/tests/translator/output/error_http_api_invalid_openapi.json index 990d3880ad..937d2232ca 100644 --- a/tests/translator/output/error_http_api_invalid_openapi.json +++ b/tests/translator/output/error_http_api_invalid_openapi.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Structure of the SAM template is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'.", "errors": [ { "errorMessage": "Resource with id [Api] is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Structure of the SAM template is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_invalid_tags_format.json b/tests/translator/output/error_http_api_invalid_tags_format.json index 7d6a7f17c0..eb5532ebaf 100644 --- a/tests/translator/output/error_http_api_invalid_tags_format.json +++ b/tests/translator/output/error_http_api_invalid_tags_format.json @@ -6,4 +6,3 @@ } ] } - \ No newline at end of file diff --git a/tests/translator/output/error_http_api_null_method.json b/tests/translator/output/error_http_api_null_method.json index 8df1a9ddf3..2baf8975bf 100644 --- a/tests/translator/output/error_http_api_null_method.json +++ b/tests/translator/output/error_http_api_null_method.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Invalid method definition (post) for path: /test" -} \ No newline at end of file +} diff --git a/tests/translator/output/error_http_api_tags.json b/tests/translator/output/error_http_api_tags.json index 97bd009e4e..425bb35557 100644 --- a/tests/translator/output/error_http_api_tags.json +++ b/tests/translator/output/error_http_api_tags.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Unable to add `Tags` because 'DefinitionBody' does not contain a valid OpenApi definition.", "errors": [ { "errorMessage": "Resource with id [Api] is invalid. Unable to add `Tags` because 'DefinitionBody' does not contain a valid OpenApi definition." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Unable to add `Tags` because 'DefinitionBody' does not contain a valid OpenApi definition." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_tags_def_uri.json b/tests/translator/output/error_http_api_tags_def_uri.json index 5b9eaa569a..6a5f63946c 100644 --- a/tests/translator/output/error_http_api_tags_def_uri.json +++ b/tests/translator/output/error_http_api_tags_def_uri.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Tags works only with inline OpenApi specified in the 'DefinitionBody' property.", "errors": [ { "errorMessage": "Resource with id [Api] is invalid. Tags works only with inline OpenApi specified in the 'DefinitionBody' property." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Tags works only with inline OpenApi specified in the 'DefinitionBody' property." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_with_cors_def_uri.json b/tests/translator/output/error_http_api_with_cors_def_uri.json index 776b9bddfd..f71c25417f 100644 --- a/tests/translator/output/error_http_api_with_cors_def_uri.json +++ b/tests/translator/output/error_http_api_with_cors_def_uri.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Cors works only with inline OpenApi specified in 'DefinitionBody' property.", "errors": [ { "errorMessage": "Resource with id [MyApi] is invalid. Cors works only with inline OpenApi specified in 'DefinitionBody' property." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. Cors works only with inline OpenApi specified in 'DefinitionBody' property." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_http_api_with_disable_api_execute_endpoint_false.json b/tests/translator/output/error_http_api_with_disable_api_execute_endpoint_false.json index 5adf87eaf6..822bd5c179 100644 --- a/tests/translator/output/error_http_api_with_disable_api_execute_endpoint_false.json +++ b/tests/translator/output/error_http_api_with_disable_api_execute_endpoint_false.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayApi] is invalid. DisableExecuteApiEndpoint works only within 'DefinitionBody' property." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_httpapi_mtls_configuration_invalid_field.json b/tests/translator/output/error_httpapi_mtls_configuration_invalid_field.json index 4aa5f273b7..60eedabe81 100644 --- a/tests/translator/output/error_httpapi_mtls_configuration_invalid_field.json +++ b/tests/translator/output/error_httpapi_mtls_configuration_invalid_field.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TruststoreVersionWrong,WrongTruststoreUri] is invalid. Available MutualTlsAuthentication fields are ['TruststoreUri', 'TruststoreVersion'].", "errors": [ { "errorMessage": "Resource with id [TruststoreVersionWrong,WrongTruststoreUri] is invalid. Available MutualTlsAuthentication fields are ['TruststoreUri', 'TruststoreVersion']." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [TruststoreVersionWrong,WrongTruststoreUri] is invalid. Available MutualTlsAuthentication fields are ['TruststoreUri', 'TruststoreVersion']." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_httpapi_mtls_configuration_invalid_type.json b/tests/translator/output/error_httpapi_mtls_configuration_invalid_type.json index 28b0e56bff..6b2026623d 100644 --- a/tests/translator/output/error_httpapi_mtls_configuration_invalid_type.json +++ b/tests/translator/output/error_httpapi_mtls_configuration_invalid_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [['TruststoreUri', 'TruststoreVersion']] is invalid. MutualTlsAuthentication must be a map with at least one of the following fields ['TruststoreUri', 'TruststoreVersion'].", "errors": [ { "errorMessage": "Resource with id [['TruststoreUri', 'TruststoreVersion']] is invalid. MutualTlsAuthentication must contains one of the following fields ['TruststoreUri', 'TruststoreVersion']." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [['TruststoreUri', 'TruststoreVersion']] is invalid. MutualTlsAuthentication must be a map with at least one of the following fields ['TruststoreUri', 'TruststoreVersion']." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_implicit_http_api_auth_any_method.json b/tests/translator/output/error_implicit_http_api_auth_any_method.json index 7064fdf5b9..1f0f898907 100644 --- a/tests/translator/output/error_implicit_http_api_auth_any_method.json +++ b/tests/translator/output/error_implicit_http_api_auth_any_method.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Could not find x-amazon-apigateway-any-method in /{domain} within DefinitionBody." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_implicit_http_api_method.json b/tests/translator/output/error_implicit_http_api_method.json index d25535b62d..cad68a31db 100644 --- a/tests/translator/output/error_implicit_http_api_method.json +++ b/tests/translator/output/error_implicit_http_api_method.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event is missing key 'Method'.", "errors": [ { "errorMessage": "Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event is missing key 'Method'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event is missing key 'Method'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_implicit_http_api_path.json b/tests/translator/output/error_implicit_http_api_path.json index c449cbbadb..17341fef8c 100644 --- a/tests/translator/output/error_implicit_http_api_path.json +++ b/tests/translator/output/error_implicit_http_api_path.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Api Event must have a String specified for 'Path'.", "errors": [ { "errorMessage": "Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Api Event must have a String specified for 'Path'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Api Event must have a String specified for 'Path'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_implicit_http_api_properties.json b/tests/translator/output/error_implicit_http_api_properties.json index 833d80e03f..26ab9f276c 100644 --- a/tests/translator/output/error_implicit_http_api_properties.json +++ b/tests/translator/output/error_implicit_http_api_properties.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue.", "errors": [ { "errorMessage": "Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HttpApiFunction] is invalid. Event with id [Basic] is invalid. Event 'Properties' must be an Object. If you're using YAML, this may be an indentation issue." + ] } diff --git a/tests/translator/output/error_invalid_config_mq.json b/tests/translator/output/error_invalid_config_mq.json index cebd93837c..0d75b6fab6 100644 --- a/tests/translator/output/error_invalid_config_mq.json +++ b/tests/translator/output/error_invalid_config_mq.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Invalid property specified in SourceAccessConfigurations for Amazon MQ event." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Invalid property specified in SourceAccessConfigurations for Amazon MQ event." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Invalid property specified in SourceAccessConfigurations for Amazon MQ event.", + "errors": [ + { + "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Invalid property specified in SourceAccessConfigurations for Amazon MQ event." + } + ] +} diff --git a/tests/translator/output/error_invalid_cors_dict.json b/tests/translator/output/error_invalid_cors_dict.json index 9dd291b3ad..8d31ddd46e 100644 --- a/tests/translator/output/error_invalid_cors_dict.json +++ b/tests/translator/output/error_invalid_cors_dict.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ServerlessRestApi] is invalid. Invalid value for 'Cors' property", "errors": [ { "errorMessage": "Resource with id [ServerlessRestApi] is invalid. Invalid value for 'Cors' property" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ServerlessRestApi] is invalid. Invalid value for 'Cors' property" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_invalid_document_empty_semantic_version.json b/tests/translator/output/error_invalid_document_empty_semantic_version.json index 7b228c1be8..d16e59a8b5 100644 --- a/tests/translator/output/error_invalid_document_empty_semantic_version.json +++ b/tests/translator/output/error_invalid_document_empty_semantic_version.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [helloworld] is invalid. Property 'SemanticVersion' cannot be blank.", "errors": [ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [helloworld] is invalid. Property 'SemanticVersion' cannot be blank." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [helloworld] is invalid. Property 'SemanticVersion' cannot be blank." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_invalid_findinmap.json b/tests/translator/output/error_invalid_findinmap.json index 6332622b84..92cb4cb3f8 100644 --- a/tests/translator/output/error_invalid_findinmap.json +++ b/tests/translator/output/error_invalid_findinmap.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Invalid FindInMap value ['ApplicationLocations', 'ap-southeast-1']. FindInMap expects an array with 3 values.", "errors": [ { "errorMessage": "Structure of the SAM template is invalid. Invalid FindInMap value ['ApplicationLocations', 'ap-southeast-1']. FindInMap expects an array with 3 values." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Invalid FindInMap value ['ApplicationLocations', 'ap-southeast-1']. FindInMap expects an array with 3 values." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_invalid_logical_id.json b/tests/translator/output/error_invalid_logical_id.json index 69369d16f7..cf07b8801a 100644 --- a/tests/translator/output/error_invalid_logical_id.json +++ b/tests/translator/output/error_invalid_logical_id.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Bad-Function-Name-@#$%^&] is invalid. Logical ids must be alphanumeric.", "errors": [ { "errorMessage": "Resource with id [Bad-Function-Name-@#$%^&] is invalid. Logical ids must be alphanumeric." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Bad-Function-Name-@#$%^&] is invalid. Logical ids must be alphanumeric." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_invalid_method_definition.json b/tests/translator/output/error_invalid_method_definition.json index 25c4f8cc1b..f3fd28e19e 100644 --- a/tests/translator/output/error_invalid_method_definition.json +++ b/tests/translator/output/error_invalid_method_definition.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of \"tags\" (['InvalidMethodDefinition']) for path / is not a valid dictionary."} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of \"tags\" (['InvalidMethodDefinition']) for path / is not a valid dictionary." +} diff --git a/tests/translator/output/error_invalid_properties.json b/tests/translator/output/error_invalid_properties.json index 5e2e3de9af..feb21144dc 100644 --- a/tests/translator/output/error_invalid_properties.json +++ b/tests/translator/output/error_invalid_properties.json @@ -5,4 +5,4 @@ "errorMessage": "Resource with id [Function] is invalid. All 'Resources' must be Objects and have a 'Properties' Object. If you're using YAML, this may be an indentation issue." } ] -} \ No newline at end of file +} diff --git a/tests/translator/output/error_invalid_resource_parameters.json b/tests/translator/output/error_invalid_resource_parameters.json index 42d21dc9d4..2e40a12d88 100644 --- a/tests/translator/output/error_invalid_resource_parameters.json +++ b/tests/translator/output/error_invalid_resource_parameters.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [UnknownPropertyInResource] is invalid. property SomeProperty not defined for resource of type AWS::Serverless::Api", "errors": [ { "errorMessage": "Resource with id [UnknownPropertyInResource] is invalid. property SomeProperty not defined for resource of type AWS::Serverless::Api" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [UnknownPropertyInResource] is invalid. property SomeProperty not defined for resource of type AWS::Serverless::Api" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_invalid_self_managed_kafka_config.json b/tests/translator/output/error_invalid_self_managed_kafka_config.json index fe7fe49bd4..ebb2a9a80d 100644 --- a/tests/translator/output/error_invalid_self_managed_kafka_config.json +++ b/tests/translator/output/error_invalid_self_managed_kafka_config.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. VPC_SUBNET and VPC_SECURITY_GROUP in SourceAccessConfigurations for SelfManagedKafka must be both provided.", "errors": [ { "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. VPC_SUBNET and VPC_SECURITY_GROUP in SourceAccessConfigurations for SelfManagedKafka must be both provided." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. VPC_SUBNET and VPC_SECURITY_GROUP in SourceAccessConfigurations for SelfManagedKafka must be both provided." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_invalid_template.json b/tests/translator/output/error_invalid_template.json index 444c782f10..9b0bea98c9 100644 --- a/tests/translator/output/error_invalid_template.json +++ b/tests/translator/output/error_invalid_template.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. 'Resources' section is required", "errors": [ { "errorMessage": "Structure of the SAM template is invalid. 'Resources' section is required" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. 'Resources' section is required" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_layer_invalid_properties.json b/tests/translator/output/error_layer_invalid_properties.json index f064188aef..691b791e0a 100644 --- a/tests/translator/output/error_layer_invalid_properties.json +++ b/tests/translator/output/error_layer_invalid_properties.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [LayerWithLicenseInfoList] is invalid. Type of property 'LicenseInfo' is invalid. Resource with id [LayerWithNoContentUri] is invalid. Missing required property 'ContentUri'. Resource with id [LayerWithRetentionPolicy] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRetentionPolicyListParam] is invalid. Could not resolve parameter for 'RetentionPolicy' or parameter is not a String. Resource with id [LayerWithRetentionPolicyParam] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRuntimesString] is invalid. Resource with id [LayerWithStringArchitecture] is invalid. Type of property 'CompatibleArchitectures' is invalid. Type of property 'CompatibleRuntimes' is invalid. Resource with id [LayerWithWrongArchitecture5b58896c5a] is invalid. CompatibleArchitectures needs to be a list of 'x86_64' or 'arm64'" - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 9. Resource with id [LayerWithLicenseInfoList] is invalid. Type of property 'LicenseInfo' is invalid. Resource with id [LayerWithNoContentUri] is invalid. Missing required property 'ContentUri'. Resource with id [LayerWithRetentionPolicy] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRetentionPolicyAsIntrinsic] is invalid. 'RetentionPolicy' does not accept intrinsic functions, please use one of the following options: ['Retain', 'Delete'] Resource with id [LayerWithRetentionPolicyListParam] is invalid. Could not resolve parameter for 'RetentionPolicy' or parameter is not a String. Resource with id [LayerWithRetentionPolicyParam] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRuntimesString] is invalid. Type of property 'CompatibleRuntimes' is invalid. Resource with id [LayerWithStringArchitecture] is invalid. Type of property 'CompatibleArchitectures' is invalid. Resource with id [LayerWithWrongArchitecture5b58896c5a] is invalid. CompatibleArchitectures needs to be a list of 'x86_64' or 'arm64'" - } + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 9. Resource with id [LayerWithLicenseInfoList] is invalid. Type of property 'LicenseInfo' is invalid. Resource with id [LayerWithNoContentUri] is invalid. Missing required property 'ContentUri'. Resource with id [LayerWithRetentionPolicy] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRetentionPolicyAsIntrinsic] is invalid. 'RetentionPolicy' does not accept intrinsic functions, please use one of the following options: ['Retain', 'Delete'] Resource with id [LayerWithRetentionPolicyListParam] is invalid. Could not resolve parameter for 'RetentionPolicy' or parameter is not a String. Resource with id [LayerWithRetentionPolicyParam] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRuntimesString] is invalid. Type of property 'CompatibleRuntimes' is invalid. Resource with id [LayerWithStringArchitecture] is invalid. Type of property 'CompatibleArchitectures' is invalid. Resource with id [LayerWithWrongArchitecture5b58896c5a] is invalid. CompatibleArchitectures needs to be a list of 'x86_64' or 'arm64'", + "errors": [ + { + "errorMessage": "Resource with id [LayerWithLicenseInfoList] is invalid. Type of property 'LicenseInfo' is invalid. Resource with id [LayerWithNoContentUri] is invalid. Missing required property 'ContentUri'. Resource with id [LayerWithRetentionPolicy] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRetentionPolicyListParam] is invalid. Could not resolve parameter for 'RetentionPolicy' or parameter is not a String. Resource with id [LayerWithRetentionPolicyParam] is invalid. 'RetentionPolicy' must be one of the following options: ['Retain', 'Delete']. Resource with id [LayerWithRuntimesString] is invalid. Resource with id [LayerWithStringArchitecture] is invalid. Type of property 'CompatibleArchitectures' is invalid. Type of property 'CompatibleRuntimes' is invalid. Resource with id [LayerWithWrongArchitecture5b58896c5a] is invalid. CompatibleArchitectures needs to be a list of 'x86_64' or 'arm64'" + } + ] +} diff --git a/tests/translator/output/error_mappings_is_null.json b/tests/translator/output/error_mappings_is_null.json index 04839dad38..100e81dc5c 100644 --- a/tests/translator/output/error_mappings_is_null.json +++ b/tests/translator/output/error_mappings_is_null.json @@ -1 +1,3 @@ -{"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. 'Mappings' or 'Parameters' is either null or not a valid dictionary."} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. 'Mappings' or 'Parameters' is either null or not a valid dictionary." +} diff --git a/tests/translator/output/error_missing_basic_auth_in_mq.json b/tests/translator/output/error_missing_basic_auth_in_mq.json index 5d55f84fe9..0e985c19de 100644 --- a/tests/translator/output/error_missing_basic_auth_in_mq.json +++ b/tests/translator/output/error_missing_basic_auth_in_mq.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH property specified in SourceAccessConfigurations for Amazon MQ event." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH property specified in SourceAccessConfigurations for Amazon MQ event." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH property specified in SourceAccessConfigurations for Amazon MQ event.", + "errors": [ + { + "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH property specified in SourceAccessConfigurations for Amazon MQ event." + } + ] } diff --git a/tests/translator/output/error_missing_basic_auth_uri_in_mq.json b/tests/translator/output/error_missing_basic_auth_uri_in_mq.json index 7a7805202b..6cacac8d18 100644 --- a/tests/translator/output/error_missing_basic_auth_uri_in_mq.json +++ b/tests/translator/output/error_missing_basic_auth_uri_in_mq.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH URI property specified in SourceAccessConfigurations for Amazon MQ event." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH URI property specified in SourceAccessConfigurations for Amazon MQ event." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH URI property specified in SourceAccessConfigurations for Amazon MQ event.", + "errors": [ + { + "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No BASIC_AUTH URI property specified in SourceAccessConfigurations for Amazon MQ event." + } + ] +} diff --git a/tests/translator/output/error_missing_broker.json b/tests/translator/output/error_missing_broker.json index 8aae6d4200..4e71d7e1a8 100644 --- a/tests/translator/output/error_missing_broker.json +++ b/tests/translator/output/error_missing_broker.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided.", + "errors": [ + { + "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." + } + ] +} diff --git a/tests/translator/output/error_missing_kafka_bootstrap_server_for_self_managed_kafka.json b/tests/translator/output/error_missing_kafka_bootstrap_server_for_self_managed_kafka.json index 834b7b9717..194a654362 100644 --- a/tests/translator/output/error_missing_kafka_bootstrap_server_for_self_managed_kafka.json +++ b/tests/translator/output/error_missing_kafka_bootstrap_server_for_self_managed_kafka.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No KafkaBootstrapServers provided for self managed kafka as an event source", "errors": [ { "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No KafkaBootstrapServers provided for self managed kafka as an event source" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No KafkaBootstrapServers provided for self managed kafka as an event source" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_missing_queue.json b/tests/translator/output/error_missing_queue.json index 90d9696fee..5ce5535bfe 100644 --- a/tests/translator/output/error_missing_queue.json +++ b/tests/translator/output/error_missing_queue.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided.", + "errors": [ + { + "errorMessage": "Resource with id [SQSFunction] is invalid. Event with id [MySqsQueue] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." + } + ] +} diff --git a/tests/translator/output/error_missing_sac_in_mq.json b/tests/translator/output/error_missing_sac_in_mq.json index 30a1ce660a..6181090f65 100644 --- a/tests/translator/output/error_missing_sac_in_mq.json +++ b/tests/translator/output/error_missing_sac_in_mq.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No SourceAccessConfigurations for Amazon MQ event provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No SourceAccessConfigurations for Amazon MQ event provided." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No SourceAccessConfigurations for Amazon MQ event provided.", + "errors": [ + { + "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. No SourceAccessConfigurations for Amazon MQ event provided." + } + ] +} diff --git a/tests/translator/output/error_missing_source_access_configurations_for_self_managed_kafka.json b/tests/translator/output/error_missing_source_access_configurations_for_self_managed_kafka.json index 7176ccc2b8..45508c42df 100644 --- a/tests/translator/output/error_missing_source_access_configurations_for_self_managed_kafka.json +++ b/tests/translator/output/error_missing_source_access_configurations_for_self_managed_kafka.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No SourceAccessConfigurations for self managed kafka event provided.", "errors": [ { "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No SourceAccessConfigurations for self managed kafka event provided." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No SourceAccessConfigurations for self managed kafka event provided." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_missing_startingposition.json b/tests/translator/output/error_missing_startingposition.json index 986f8b072f..1aaa064671 100644 --- a/tests/translator/output/error_missing_startingposition.json +++ b/tests/translator/output/error_missing_startingposition.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis, DynamoDB and MSK." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis, DynamoDB and MSK." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis, DynamoDB and MSK.", + "errors": [ + { + "errorMessage": "Resource with id [KinesisFunction] is invalid. Event with id [MyKinesisStream] is invalid. StartingPosition is required for Kinesis, DynamoDB and MSK." + } + ] +} diff --git a/tests/translator/output/error_missing_stream.json b/tests/translator/output/error_missing_stream.json index 40071cc4c4..d8e00ba19a 100644 --- a/tests/translator/output/error_missing_stream.json +++ b/tests/translator/output/error_missing_stream.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided.", + "errors": [ + { + "errorMessage": "Resource with id [DynamoDBFunction] is invalid. Event with id [MyDDBStream] is invalid. No Queue (for SQS) or Stream (for Kinesis, DynamoDB or MSK) or Broker (for Amazon MQ) provided." + } + ] +} diff --git a/tests/translator/output/error_missing_topics_for_self_managed_kafka.json b/tests/translator/output/error_missing_topics_for_self_managed_kafka.json index 8aceb3a0a3..b339b30858 100644 --- a/tests/translator/output/error_missing_topics_for_self_managed_kafka.json +++ b/tests/translator/output/error_missing_topics_for_self_managed_kafka.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No Topics provided for self managed kafka as an event source", "errors": [ { "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No Topics provided for self managed kafka as an event source" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. No Topics provided for self managed kafka as an event source" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_multiple_auth_mechanism_self_managed_kafka_config.json b/tests/translator/output/error_multiple_auth_mechanism_self_managed_kafka_config.json index bc3da87976..13b26fcab4 100644 --- a/tests/translator/output/error_multiple_auth_mechanism_self_managed_kafka_config.json +++ b/tests/translator/output/error_multiple_auth_mechanism_self_managed_kafka_config.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Multiple auth mechanism properties specified in SourceAccessConfigurations for self managed kafka event.", "errors": [ { "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Multiple auth mechanism properties specified in SourceAccessConfigurations for self managed kafka event." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Multiple auth mechanism properties specified in SourceAccessConfigurations for self managed kafka event." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_multiple_basic_auth_in_mq.json b/tests/translator/output/error_multiple_basic_auth_in_mq.json index ab46b0eba1..3a6f8558d2 100644 --- a/tests/translator/output/error_multiple_basic_auth_in_mq.json +++ b/tests/translator/output/error_multiple_basic_auth_in_mq.json @@ -1,6 +1,8 @@ { - "errors": [{ - "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Multiple BASIC_AUTH properties specified in SourceAccessConfigurations for Amazon MQ event." - }], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Multiple BASIC_AUTH properties specified in SourceAccessConfigurations for Amazon MQ event." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Multiple BASIC_AUTH properties specified in SourceAccessConfigurations for Amazon MQ event.", + "errors": [ + { + "errorMessage": "Resource with id [MQFunction] is invalid. Event with id [MyMQQueue] is invalid. Multiple BASIC_AUTH properties specified in SourceAccessConfigurations for Amazon MQ event." + } + ] } diff --git a/tests/translator/output/error_multiple_resource_errors.json b/tests/translator/output/error_multiple_resource_errors.json index ec68793ae4..c27314d979 100644 --- a/tests/translator/output/error_multiple_resource_errors.json +++ b/tests/translator/output/error_multiple_resource_errors.json @@ -1,4 +1,5 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [BadCodeUriFunction] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [BadCodeUriTypeFunction] is invalid. 'CodeUri' requires Bucket and Key properties to be specified. Resource with id [BadDefinitionUriApi] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [BadDefinitionUriTypeApi] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified. Resource with id [ExternalS3Function] is invalid. Event with id [S3Event] is invalid. S3 events must reference an S3 bucket in the same template.", "errors": [ { "errorMessage": "Resource with id [BadCodeUriTypeFunction] is invalid. 'CodeUri' requires Bucket and Key properties to be specified." @@ -15,6 +16,5 @@ { "errorMessage": "Resource with id [BadDefinitionUriTypeApi] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 5. Resource with id [BadCodeUriFunction] is invalid. 'CodeUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [BadCodeUriTypeFunction] is invalid. 'CodeUri' requires Bucket and Key properties to be specified. Resource with id [BadDefinitionUriApi] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter. Resource with id [BadDefinitionUriTypeApi] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified. Resource with id [ExternalS3Function] is invalid. Event with id [S3Event] is invalid. S3 events must reference an S3 bucket in the same template." + ] } diff --git a/tests/translator/output/error_multiple_topics_for_self_managed_kafka.json b/tests/translator/output/error_multiple_topics_for_self_managed_kafka.json index e2d372be2f..5548c0b166 100644 --- a/tests/translator/output/error_multiple_topics_for_self_managed_kafka.json +++ b/tests/translator/output/error_multiple_topics_for_self_managed_kafka.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Topics for self managed kafka only supports single configuration entry.", "errors": [ { "errorMessage": "Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Topics for self managed kafka only supports single configuration entry." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [KafkaFunction] is invalid. Event with id [MyKafkaCluster] is invalid. Topics for self managed kafka only supports single configuration entry." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_null_application_id.json b/tests/translator/output/error_null_application_id.json index 579a684c8f..bae44f9c90 100644 --- a/tests/translator/output/error_null_application_id.json +++ b/tests/translator/output/error_null_application_id.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [Application] is invalid. Property 'ApplicationId' cannot be blank." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Application] is invalid. Property 'ApplicationId' cannot be blank." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Application] is invalid. Property 'ApplicationId' cannot be blank.", + "errors": [ + { + "errorMessage": "Resource with id [Application] is invalid. Property 'ApplicationId' cannot be blank." + } + ] +} diff --git a/tests/translator/output/error_null_method_definition.json b/tests/translator/output/error_null_method_definition.json index ae7f7eadc3..0b7235865b 100644 --- a/tests/translator/output/error_null_method_definition.json +++ b/tests/translator/output/error_null_method_definition.json @@ -1 +1,3 @@ -{"errorMessage":"Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of \"get\" (None) for path / is not a valid dictionary."} \ No newline at end of file +{ + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of \"get\" (None) for path / is not a valid dictionary." +} diff --git a/tests/translator/output/error_reserved_sam_tag.json b/tests/translator/output/error_reserved_sam_tag.json index 4ff8d06bbe..cd4ab4c66e 100644 --- a/tests/translator/output/error_reserved_sam_tag.json +++ b/tests/translator/output/error_reserved_sam_tag.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AlexaSkillFunc] is invalid. lambda:createdBy is a reserved Tag key name and cannot be set on your resource. Please change the tag key in the input. Resource with id [SomeApplication] is invalid. lambda:createdBy is a reserved Tag key name and cannot be set on your resource. Please change the tag key in the input.", "errors": [ { "errorMessage": "Resource with id [AlexaSkillFunc] is invalid. lambda:createdBy is a reserved Tag key name and cannot be set on your resource. Please change the tag key in the input. Resource with id [SomeApplication] is invalid. stack:createdBy is a reserved Tag key name and cannot be set on your resource. Please change the tag key in the input." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AlexaSkillFunc] is invalid. lambda:createdBy is a reserved Tag key name and cannot be set on your resource. Please change the tag key in the input. Resource with id [SomeApplication] is invalid. lambda:createdBy is a reserved Tag key name and cannot be set on your resource. Please change the tag key in the input." + ] } diff --git a/tests/translator/output/error_resource_not_dict.json b/tests/translator/output/error_resource_not_dict.json index 47272f87db..6da5b6269a 100644 --- a/tests/translator/output/error_resource_not_dict.json +++ b/tests/translator/output/error_resource_not_dict.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. All 'Resources' must be Objects. If you're using YAML, this may be an indentation issue.", "errors": [ { "errorMessage": "Structure of the SAM template is invalid. All 'Resources' must be Objects. If you're using YAML, this may be an indentation issue." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. All 'Resources' must be Objects. If you're using YAML, this may be an indentation issue." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_resource_policy_not_dict.json b/tests/translator/output/error_resource_policy_not_dict.json index 5ed2d9c8ad..7f86db9c55 100644 --- a/tests/translator/output/error_resource_policy_not_dict.json +++ b/tests/translator/output/error_resource_policy_not_dict.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. ResourcePolicy must be a map (ResourcePolicyStatement)." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_resource_policy_not_dict_empty_api.json b/tests/translator/output/error_resource_policy_not_dict_empty_api.json index 5ed2d9c8ad..7f86db9c55 100644 --- a/tests/translator/output/error_resource_policy_not_dict_empty_api.json +++ b/tests/translator/output/error_resource_policy_not_dict_empty_api.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. ResourcePolicy must be a map (ResourcePolicyStatement)." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_resource_properties_not_dict.json b/tests/translator/output/error_resource_properties_not_dict.json index a7929ef224..feb21144dc 100644 --- a/tests/translator/output/error_resource_properties_not_dict.json +++ b/tests/translator/output/error_resource_properties_not_dict.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. All 'Resources' must be Objects and have a 'Properties' Object. If you're using YAML, this may be an indentation issue.", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. All 'Resources' must be Objects and have a 'Properties' Object. If you're using YAML, this may be an indentation issue." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. All 'Resources' must be Objects and have a 'Properties' Object. If you're using YAML, this may be an indentation issue." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_s3_lambda_configuration_invalid_type.json b/tests/translator/output/error_s3_lambda_configuration_invalid_type.json index e5d7c04809..03679d6e92 100644 --- a/tests/translator/output/error_s3_lambda_configuration_invalid_type.json +++ b/tests/translator/output/error_s3_lambda_configuration_invalid_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AnotherBucket] is invalid. Invalid type for NotificationConfiguration. Resource with id [RandomBucket] is invalid. Invalid type for LambdaConfigurations. Must be a list.", "errors": [ { "errorMessage": "Resource with id [AppFunctionS3Event] is invalid. Invalid type for LambdaConfigurations. Must be a list." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 2. Resource with id [AnotherBucket] is invalid. Invalid type for NotificationConfiguration. Resource with id [RandomBucket] is invalid. Invalid type for LambdaConfigurations. Must be a list." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_s3_not_in_template.json b/tests/translator/output/error_s3_not_in_template.json index a414af432b..95fc000b4a 100644 --- a/tests/translator/output/error_s3_not_in_template.json +++ b/tests/translator/output/error_s3_not_in_template.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [ImageBucket] is invalid. S3 events must reference an S3 bucket in the same template.", "errors": [ { "errorMessage": "Resource with id [Function] is invalid. Event with id [ImageBucket] is invalid. S3 events must reference an S3 bucket in the same template." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Function] is invalid. Event with id [ImageBucket] is invalid. S3 events must reference an S3 bucket in the same template." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_sns_intrinsics.json b/tests/translator/output/error_sns_intrinsics.json index ad95a1a668..12d0efba17 100644 --- a/tests/translator/output/error_sns_intrinsics.json +++ b/tests/translator/output/error_sns_intrinsics.json @@ -5,4 +5,4 @@ "errorMessage": "Resource with id [SaveNotificationFunction] is invalid. Event with id [NotificationTopic] is invalid. No QueueARN or QueueURL provided." } ] -} \ No newline at end of file +} diff --git a/tests/translator/output/error_sns_not_in_template.json b/tests/translator/output/error_sns_not_in_template.json index e76ad56a10..f00d6113b5 100644 --- a/tests/translator/output/error_sns_not_in_template.json +++ b/tests/translator/output/error_sns_not_in_template.json @@ -5,4 +5,4 @@ "errorMessage": "Resource with id [Function] is invalid. Event with id [NotificationTopic] is invalid. SNS events must reference an SNS topic in the same template." } ] -} \ No newline at end of file +} diff --git a/tests/translator/output/error_state_machine_definition_string.json b/tests/translator/output/error_state_machine_definition_string.json index ff05e29ecd..e35da68189 100644 --- a/tests/translator/output/error_state_machine_definition_string.json +++ b/tests/translator/output/error_state_machine_definition_string.json @@ -1,9 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [StateMachine] is invalid. Type of property 'Definition' is invalid." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [StateMachine] is invalid. Type of property 'Definition' is invalid." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [StateMachine] is invalid. Type of property 'Definition' is invalid.", + "errors": [ + { + "errorMessage": "Resource with id [StateMachine] is invalid. Type of property 'Definition' is invalid." + } + ] } - \ No newline at end of file diff --git a/tests/translator/output/error_state_machine_invalid_s3_object.json b/tests/translator/output/error_state_machine_invalid_s3_object.json index c07a486ceb..af082cde18 100644 --- a/tests/translator/output/error_state_machine_invalid_s3_object.json +++ b/tests/translator/output/error_state_machine_invalid_s3_object.json @@ -1,9 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [StateMachine] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [StateMachine] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [StateMachine] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified.", + "errors": [ + { + "errorMessage": "Resource with id [StateMachine] is invalid. 'DefinitionUri' requires Bucket and Key properties to be specified." + } + ] } - \ No newline at end of file diff --git a/tests/translator/output/error_state_machine_invalid_s3_string.json b/tests/translator/output/error_state_machine_invalid_s3_string.json index 1292f30119..c3b40fc01c 100644 --- a/tests/translator/output/error_state_machine_invalid_s3_string.json +++ b/tests/translator/output/error_state_machine_invalid_s3_string.json @@ -1,9 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [StateMachine] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [StateMachine] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [StateMachine] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter.", + "errors": [ + { + "errorMessage": "Resource with id [StateMachine] is invalid. 'DefinitionUri' is not a valid S3 Uri of the form 's3://bucket/key' with optional versionId query parameter." + } + ] } - \ No newline at end of file diff --git a/tests/translator/output/error_state_machine_with_api_auth_none.json b/tests/translator/output/error_state_machine_with_api_auth_none.json index 54a0f34876..e53ff95388 100644 --- a/tests/translator/output/error_state_machine_with_api_auth_none.json +++ b/tests/translator/output/error_state_machine_with_api_auth_none.json @@ -1,8 +1,8 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer on API method [post] for path [/startWithLambdaToken] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified.", - "errors": [ - { - "errorMessage": "Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer on API method [post] for path [/startWithLambdaToken] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified." - } - ] -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer on API method [post] for path [/startWithLambdaToken] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified.", + "errors": [ + { + "errorMessage": "Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer on API method [post] for path [/startWithLambdaToken] because 'NONE' is only a valid value when a DefaultAuthorizer on the API is specified." + } + ] +} diff --git a/tests/translator/output/error_state_machine_with_cwe_both_dlq_property_provided.json b/tests/translator/output/error_state_machine_with_cwe_both_dlq_property_provided.json index 10180f3571..9e8df0ba2d 100644 --- a/tests/translator/output/error_state_machine_with_cwe_both_dlq_property_provided.json +++ b/tests/translator/output/error_state_machine_with_cwe_both_dlq_property_provided.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" +} diff --git a/tests/translator/output/error_state_machine_with_cwe_invalid_dlq_type.json b/tests/translator/output/error_state_machine_with_cwe_invalid_dlq_type.json index 3e132e754b..220c818c18 100644 --- a/tests/translator/output/error_state_machine_with_cwe_invalid_dlq_type.json +++ b/tests/translator/output/error_state_machine_with_cwe_invalid_dlq_type.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" +} diff --git a/tests/translator/output/error_state_machine_with_cwe_missing_dlq_property.json b/tests/translator/output/error_state_machine_with_cwe_missing_dlq_property.json index 39b0165200..2f0cf0b1d7 100644 --- a/tests/translator/output/error_state_machine_with_cwe_missing_dlq_property.json +++ b/tests/translator/output/error_state_machine_with_cwe_missing_dlq_property.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" +} diff --git a/tests/translator/output/error_state_machine_with_eb_dlq_generated_intrinsic_function.json b/tests/translator/output/error_state_machine_with_eb_dlq_generated_intrinsic_function.json index 11787a03cf..d1cd900cdb 100644 --- a/tests/translator/output/error_state_machine_with_eb_dlq_generated_intrinsic_function.json +++ b/tests/translator/output/error_state_machine_with_eb_dlq_generated_intrinsic_function.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. QueueLogicalId must be a string", "errors": [ { "errorMessage": "Event with id [StateMachineCWEvent] is invalid. QueueLogicalId must be a string" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineCWEvent] is invalid. QueueLogicalId must be a string" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_state_machine_with_invalid_default_authorizer.json b/tests/translator/output/error_state_machine_with_invalid_default_authorizer.json index b3394c79be..77b8a53e78 100644 --- a/tests/translator/output/error_state_machine_with_invalid_default_authorizer.json +++ b/tests/translator/output/error_state_machine_with_invalid_default_authorizer.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. DefaultAuthorizer is not a string." -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. DefaultAuthorizer is not a string." +} diff --git a/tests/translator/output/error_state_machine_with_invalid_schedule_event.json b/tests/translator/output/error_state_machine_with_invalid_schedule_event.json index 7afaae7c0d..f2d49c52d1 100644 --- a/tests/translator/output/error_state_machine_with_invalid_schedule_event.json +++ b/tests/translator/output/error_state_machine_with_invalid_schedule_event.json @@ -1,8 +1,8 @@ { - "errors": [ - { - "errorMessage": "Resource with id [ScheduledStateMachine] is invalid. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified." - } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified.", + "errors": [ + { + "errorMessage": "Resource with id [ScheduledStateMachine] is invalid. Event with id [Schedule1] is invalid. State and Enabled Properties cannot both be specified." + } + ] } diff --git a/tests/translator/output/error_state_machine_with_no_api_authorizers.json b/tests/translator/output/error_state_machine_with_no_api_authorizers.json index 600097f944..8f46cf7575 100644 --- a/tests/translator/output/error_state_machine_with_no_api_authorizers.json +++ b/tests/translator/output/error_state_machine_with_no_api_authorizers.json @@ -1,8 +1,8 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because the related API does not define any Authorizers.", - "errors": [ - { - "errorMessage": "Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because the related API does not define any Authorizers." - } - ] -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because the related API does not define any Authorizers.", + "errors": [ + { + "errorMessage": "Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because the related API does not define any Authorizers." + } + ] +} diff --git a/tests/translator/output/error_state_machine_with_schedule_both_dlq_property_provided.json b/tests/translator/output/error_state_machine_with_schedule_both_dlq_property_provided.json index 932c2adc7a..3d4947cadf 100644 --- a/tests/translator/output/error_state_machine_with_schedule_both_dlq_property_provided.json +++ b/tests/translator/output/error_state_machine_with_schedule_both_dlq_property_provided.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. You can either define 'Arn' or 'Type' property of DeadLetterConfig" +} diff --git a/tests/translator/output/error_state_machine_with_schedule_dlq_generated_intrinsic_function.json b/tests/translator/output/error_state_machine_with_schedule_dlq_generated_intrinsic_function.json index 947f723e75..247eecb7ac 100644 --- a/tests/translator/output/error_state_machine_with_schedule_dlq_generated_intrinsic_function.json +++ b/tests/translator/output/error_state_machine_with_schedule_dlq_generated_intrinsic_function.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. QueueLogicalId must be a string", "errors": [ { "errorMessage": "Event with id [StateMachineCWEvent] is invalid. QueueLogicalId must be a string" } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. QueueLogicalId must be a string" -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_state_machine_with_schedule_invalid_dlq_type.json b/tests/translator/output/error_state_machine_with_schedule_invalid_dlq_type.json index c429367c2d..568d6ea449 100644 --- a/tests/translator/output/error_state_machine_with_schedule_invalid_dlq_type.json +++ b/tests/translator/output/error_state_machine_with_schedule_invalid_dlq_type.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. The only valid value for 'Type' property of DeadLetterConfig is 'SQS'" +} diff --git a/tests/translator/output/error_state_machine_with_schedule_missing_dlq_property.json b/tests/translator/output/error_state_machine_with_schedule_missing_dlq_property.json index ac66076034..f6f55cf336 100644 --- a/tests/translator/output/error_state_machine_with_schedule_missing_dlq_property.json +++ b/tests/translator/output/error_state_machine_with_schedule_missing_dlq_property.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [StateMachineScheduleEvent] is invalid. No 'Arn' or 'Type' property provided for DeadLetterConfig" +} diff --git a/tests/translator/output/error_state_machine_with_undefined_api_authorizer.json b/tests/translator/output/error_state_machine_with_undefined_api_authorizer.json index f11a5fc932..b7d1560f2e 100644 --- a/tests/translator/output/error_state_machine_with_undefined_api_authorizer.json +++ b/tests/translator/output/error_state_machine_with_undefined_api_authorizer.json @@ -1,8 +1,8 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because it wasn't defined in the API's Authorizers.", - "errors": [ - { - "errorMessage": "Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because it wasn't defined in the API's Authorizers." - } - ] -} \ No newline at end of file + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because it wasn't defined in the API's Authorizers.", + "errors": [ + { + "errorMessage": "Event with id [WithLambdaTokenAuth] is invalid. Unable to set Authorizer [MyUndefinedAuthorizer] on API method [post] for path [/startWithLambdaToken] because it wasn't defined in the API's Authorizers." + } + ] +} diff --git a/tests/translator/output/error_swagger_security_not_dict.json b/tests/translator/output/error_swagger_security_not_dict.json index bcf03cb96d..11d14da3bb 100644 --- a/tests/translator/output/error_swagger_security_not_dict.json +++ b/tests/translator/output/error_swagger_security_not_dict.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. CustomAuthorizer in Security for path /path method put is not a valid dictionary." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_swagger_security_not_dict_with_api_key_required.json b/tests/translator/output/error_swagger_security_not_dict_with_api_key_required.json index b6fac4d527..604004a0e8 100644 --- a/tests/translator/output/error_swagger_security_not_dict_with_api_key_required.json +++ b/tests/translator/output/error_swagger_security_not_dict_with_api_key_required.json @@ -1,3 +1,3 @@ { "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. [] in Security for path /path method put is not a valid dictionary." -} \ No newline at end of file +} diff --git a/tests/translator/output/error_table_invalid_attributetype.json b/tests/translator/output/error_table_invalid_attributetype.json index 17a6a20851..2884e03aad 100644 --- a/tests/translator/output/error_table_invalid_attributetype.json +++ b/tests/translator/output/error_table_invalid_attributetype.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. Invalid 'Type' \"bogus\".", "errors": [ { "errorMessage": "Resource with id [Table] is invalid. Invalid 'Type' \"bogus\"." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. Invalid 'Type' \"bogus\"." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_table_primary_key_missing_name.json b/tests/translator/output/error_table_primary_key_missing_name.json index de5a712c21..445889aa7d 100644 --- a/tests/translator/output/error_table_primary_key_missing_name.json +++ b/tests/translator/output/error_table_primary_key_missing_name.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'.", "errors": [ { "errorMessage": "Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/error_table_primary_key_missing_type.json b/tests/translator/output/error_table_primary_key_missing_type.json index de5a712c21..445889aa7d 100644 --- a/tests/translator/output/error_table_primary_key_missing_type.json +++ b/tests/translator/output/error_table_primary_key_missing_type.json @@ -1,8 +1,8 @@ { + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'.", "errors": [ { "errorMessage": "Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." } - ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Table] is invalid. 'PrimaryKey' is missing required Property 'Name' or 'Type'." -} \ No newline at end of file + ] +} diff --git a/tests/translator/output/eventbridgerule.json b/tests/translator/output/eventbridgerule.json index 0ea8edf56a..cc8dfdc259 100644 --- a/tests/translator/output/eventbridgerule.json +++ b/tests/translator/output/eventbridgerule.json @@ -1,185 +1,185 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/eventbridgerule_schedule_properties.json b/tests/translator/output/eventbridgerule_schedule_properties.json index 2ea3bd9c1e..939ae82702 100644 --- a/tests/translator/output/eventbridgerule_schedule_properties.json +++ b/tests/translator/output/eventbridgerule_schedule_properties.json @@ -1,93 +1,120 @@ { "Resources": { - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", + "ScheduledFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -95,93 +122,66 @@ "terminated" ] } - }, + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Name": "test-schedule", - "Description": "Test Schedule", - "State": "ENABLED", - "Targets": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/eventbridgerule_with_dlq.json b/tests/translator/output/eventbridgerule_with_dlq.json index 5e9bd4ab01..a7abb393b0 100644 --- a/tests/translator/output/eventbridgerule_with_dlq.json +++ b/tests/translator/output/eventbridgerule_with_dlq.json @@ -1,240 +1,240 @@ { "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ScheduledFunctionScheduleQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Queues": [ + "ScheduleExpression": "rate(1 minute)", + "State": "ENABLED", + "Targets": [ { - "Ref": "ScheduledFunctionScheduleQueue" + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "DeadLetterConfig": { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunctionScheduleQueue", + "Arn" + ] + } + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" } - ], + ] + }, + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionScheduleQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "ScheduledFunctionScheduleQueuePolicy": { + "Properties": { "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "ScheduledFunctionScheduleQueue", - "Arn" - ] - }, - "Effect": "Allow", + "Action": "sqs:SendMessage", "Condition": { "ArnEquals": { "aws:SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } } - }, + }, + "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "ScheduledFunctionScheduleQueue", + "Arn" + ] } } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "ScheduledFunctionScheduleQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "TriggeredFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TriggeredFunctionRole", + "Arn" ] - } - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", - "State" : "ENABLED", + }, + "State": "ENABLED", "Targets": [ { - "DeadLetterConfig": { - "Arn": "ARN" - }, - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - } + }, + "DeadLetterConfig": { + "Arn": "ARN" + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget" } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "TriggeredFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", + "TriggeredFunctionOnTerminate", "Arn" ] } - } - }, - "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule", - "Arn" - ] - } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { - "Fn::GetAtt": [ - "ScheduledFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionScheduleQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { - "Fn::GetAtt": [ - "TriggeredFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "State" : "ENABLED", - "Targets": [ - { - "DeadLetterConfig": { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunctionScheduleQueue", - "Arn" - ] - } - }, - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/eventbridgerule_with_retry_policy.json b/tests/translator/output/eventbridgerule_with_retry_policy.json index 2cc7e5d9c1..3125ae432f 100644 --- a/tests/translator/output/eventbridgerule_with_retry_policy.json +++ b/tests/translator/output/eventbridgerule_with_retry_policy.json @@ -1,189 +1,189 @@ { "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "TriggeredFunctionOnTerminatePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "TriggeredFunction" - }, - "SourceArn": { - "Fn::GetAtt": [ - "TriggeredFunctionOnTerminate", - "Arn" - ] - } - } - }, + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, "ScheduledFunctionSchedulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ScheduledFunction" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ - "ScheduledFunctionSchedule", + "ScheduledFunctionSchedule", "Arn" ] } - } - }, - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Permission" + }, + "TriggeredFunction": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ScheduledFunctionRole", + "TriggeredFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "TriggeredFunctionOnTerminate": { - "Type": "AWS::Events::Rule", "Properties": { + "EventBusName": "ExternalEventBridge", "EventPattern": { "detail": { "state": [ "terminated" ] } - }, - "EventBusName": "ExternalEventBridge", + }, "Targets": [ { - "Id": "TriggeredFunctionOnTerminateLambdaTarget", "Arn": { "Fn::GetAtt": [ - "TriggeredFunction", + "TriggeredFunction", "Arn" ] - }, + }, + "Id": "TriggeredFunctionOnTerminateLambdaTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 200, + "MaximumEventAgeInSeconds": 200, "MaximumRetryAttempts": 3 } } ] - } - }, - "TriggeredFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Events::Rule" + }, + "TriggeredFunctionOnTerminatePermission": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Role": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TriggeredFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "TriggeredFunctionRole", + "TriggeredFunctionOnTerminate", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + } + }, + "Type": "AWS::Lambda::Permission" + }, "TriggeredFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ScheduledFunctionSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "ScheduledFunctionScheduleLambdaTarget", - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/explicit_api.json b/tests/translator/output/explicit_api.json index cfc5f2e0f2..95c019102d 100644 --- a/tests/translator/output/explicit_api.json +++ b/tests/translator/output/explicit_api.json @@ -1,163 +1,162 @@ { "Parameters": { - "something": { - "Default": "something", - "Type": "String" - }, "MyStageName": { - "Default": "Production", + "Default": "Production", + "Type": "String" + }, + "something": { + "Default": "something", "Type": "String" } - }, + }, "Resources": { - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "ApiWithInlineSwagger": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "webpage.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + "Body": { + "a": "inline swagger", + "this": "is" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiWithInlineSwaggerDeployment09cda3d97b": { + "Properties": { + "Description": "RestApi deployment id: 09cda3d97b008bed7bd4ebb1b5304ed622492941", + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiWithInlineSwaggerStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithInlineSwaggerDeployment09cda3d97b" - }, + }, "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, + }, "StageName": { "Ref": "MyStageName" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "Name": "MyGetApi" + }, + "Type": "AWS::ApiGateway::RestApi" }, "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", "RestApiId": { "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + }, "StageName": "Stage" - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "EndpointUri": { + "Ref": "something" + }, + "EndpointUri2": "http://example.com" + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "webpage.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "inline swagger" - } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "GetHtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "GetHtmlApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Name": "MyGetApi" - } - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "EndpointUri": { - "Ref": "something" - }, - "EndpointUri2": "http://example.com" - }, - "StageName": { - "Ref": "MyStageName" - } - } - }, - "ApiWithInlineSwaggerDeployment09cda3d97b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { "Properties": { - "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 09cda3d97b008bed7bd4ebb1b5304ed622492941", - "StageName": "Stage" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/explicit_api_openapi_3.json b/tests/translator/output/explicit_api_openapi_3.json index 4397a036ca..5aac47a166 100644 --- a/tests/translator/output/explicit_api_openapi_3.json +++ b/tests/translator/output/explicit_api_openapi_3.json @@ -1,162 +1,161 @@ { "Parameters": { - "something": { - "Default": "something", - "Type": "String" - }, "MyStageName": { - "Default": "Production", + "Default": "Production", + "Type": "String" + }, + "something": { + "Default": "something", "Type": "String" } - }, + }, "Resources": { - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "ApiWithInlineSwagger": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "webpage.zip" - }, - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + "Body": { + "a": "inline swagger", + "this": "is" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiWithInlineSwaggerDeployment74abcb3a5b": { + "Properties": { + "Description": "RestApi deployment id: 74abcb3a5bbe7ad58dfc543740af3be156736130", + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiWithInlineSwaggerStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ApiWithInlineSwaggerDeployment74abcb3a5b" - }, + }, "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, + }, "StageName": { "Ref": "MyStageName" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "Name": "MyGetApi" + }, + "Type": "AWS::ApiGateway::RestApi" }, "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", "RestApiId": { "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + }, "StageName": "Stage" - } - }, - "ApiWithInlineSwaggerDeployment74abcb3a5b": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 74abcb3a5bbe7ad58dfc543740af3be156736130" - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "EndpointUri": { + "Ref": "something" + }, + "EndpointUri2": "http://example.com" + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "webpage.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "this": "is", - "a": "inline swagger" - } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionGetHtmlPermissionStage": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "GetHtmlFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "GetHtmlApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Name": "MyGetApi" - } - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "EndpointUri": { - "Ref": "something" - }, - "EndpointUri2": "http://example.com" - }, - "StageName": { - "Ref": "MyStageName" - } - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/explicit_api_with_invalid_events_config.json b/tests/translator/output/explicit_api_with_invalid_events_config.json index 854035d366..07e5e6ac51 100644 --- a/tests/translator/output/explicit_api_with_invalid_events_config.json +++ b/tests/translator/output/explicit_api_with_invalid_events_config.json @@ -1,126 +1,126 @@ { "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionAddApiPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", - { - "__Stage__": "*", - "__ApiId__": "ApiWithInlineSwagger" - } - ] - } - } - }, - "ApiWithInlineSwaggerProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ApiWithInlineSwaggerDeployment22d399868d" - }, - "RestApiId": { - "Ref": "ApiWithInlineSwagger" - }, - "StageName": "Prod" - } - }, "ApiWithInlineSwagger": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/foo": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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" } - } - }, + }, + "Type": "AWS::ApiGateway::RestApi" + }, "ApiWithInlineSwaggerDeployment22d399868d": { - "Type": "AWS::ApiGateway::Deployment", "Properties": { + "Description": "RestApi deployment id: 22d399868d5755a0d5204deae1ee870cf95a7737", "RestApiId": { "Ref": "ApiWithInlineSwagger" - }, - "Description": "RestApi deployment id: 22d399868d5755a0d5204deae1ee870cf95a7737", + }, "StageName": "Stage" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiWithInlineSwaggerProdStage": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "DeploymentId": { + "Ref": "ApiWithInlineSwaggerDeployment22d399868d" + }, + "RestApiId": { + "Ref": "ApiWithInlineSwagger" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAddApiPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + { + "__ApiId__": "ApiWithInlineSwagger", + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/explicit_http_api.json b/tests/translator/output/explicit_http_api.json index 8a8a6dab6a..852b31e08f 100644 --- a/tests/translator/output/explicit_http_api.json +++ b/tests/translator/output/explicit_http_api.json @@ -1,39 +1,12 @@ { "Resources": { - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ "HttpApiFunctionRole", @@ -43,110 +16,37 @@ "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", + "HttpApiFunctionBasePathPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "HttpApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "title": { - "Fn::Sub": "${AWS::StackName}-Apiv2" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "ANY", - "type": "http_proxy", - "uri": "https://www.alphavantage.co/", - "payloadFormatVersion": "1.0" - }, - "isDefaultRoute": true, - "security": [ - { - "OAuth2": [] - } - ] - } - }, - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "OAuth2": [] - } - ], - "responses": {} - } - } - }, - "openapi": "3.0", - "components": { - "securitySchemes": { - "OAuth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Ref": "MyApi2" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -159,63 +59,74 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "HttpApiFunctionBasePathPermission": { - "Type": "AWS::Lambda::Permission", + "HttpApiFunctionSimpleCasePermission": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "HttpApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { - "Ref": "MyApi2" - } + "Ref": "MyApi" + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { - "FailOnWarnings": true, "Body": { + "components": { + "securitySchemes": { + "OAuth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, "isDefaultRoute": true, + "responses": {}, "security": [ { "OAuth2": [ @@ -223,23 +134,85 @@ ] } ], - "responses": {} + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } } }, - "openapi": "3.0.1", + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + }, + "FailOnWarnings": true + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2": { + "Properties": { + "Body": { "components": { "securitySchemes": { "OAuth2": { "type": "oauth2", "x-amazon-apigateway-authorizer": { "identitySource": "$request.querystring.param", - "type": "jwt", "jwtConfiguration": { "audience": [ "MyApi" ], "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Apiv2" + } + }, + "openapi": "3.0", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "security": [ + { + "OAuth2": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "payloadFormatVersion": "1.0", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/" + } + } + }, + "/": { + "get": { + "responses": {}, + "security": [ + { + "OAuth2": [] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } } } @@ -252,7 +225,34 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/explicit_http_api_minimum.json b/tests/translator/output/explicit_http_api_minimum.json index 37be2617d8..424c93a390 100644 --- a/tests/translator/output/explicit_http_api_minimum.json +++ b/tests/translator/output/explicit_http_api_minimum.json @@ -1,161 +1,161 @@ { "Resources": { + "Api": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "Api" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "Api": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], - "paths": {}, - "openapi": "3.0.1" - } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, - "openapi": "3.0.1" + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ] } - } - }, + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "Api" - }, - "AutoDeploy": true, - "StageName": "$default", + }, + "AutoDeploy": true, + "StageName": "$default", "Tags": { "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/function_concurrency.json b/tests/translator/output/function_concurrency.json index afd5f36c74..a101d795bb 100644 --- a/tests/translator/output/function_concurrency.json +++ b/tests/translator/output/function_concurrency.json @@ -5,20 +5,35 @@ } }, "Resources": { - "ConcurrentFunctionRole": { - "Type": "AWS::IAM::Role", + "AnotherFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": { + "Ref": "Concurrency" + }, + "Role": { + "Fn::GetAtt": [ + "AnotherFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "AnotherFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -30,18 +45,30 @@ "lambda.amazonaws.com" ] } - }] - } - } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ConcurrentFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "ConcurrentFunctionRole", @@ -49,27 +76,18 @@ ] }, "Runtime": "python2.7", - "ReservedConcurrentExecutions": 100, - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "AnotherFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ConcurrentFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -81,33 +99,21 @@ "lambda.amazonaws.com" ] } - }] - } - } - }, - "AnotherFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + } + ], + "Version": "2012-10-17" }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "AnotherFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "ReservedConcurrentExecutions": { - "Ref": "Concurrency" - }, - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_event_conditions.json b/tests/translator/output/function_event_conditions.json index 4926995a99..1bffc101b4 100644 --- a/tests/translator/output/function_event_conditions.json +++ b/tests/translator/output/function_event_conditions.json @@ -8,174 +8,293 @@ } }, "Resources": { - "MyAwesomeFunctionAliasLive": { - "Type": "AWS::Lambda::Alias", - "Condition": "MyCondition", + "FunctionOne": { "Properties": { - "FunctionVersion": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { "Fn::GetAtt": [ - "MyAwesomeFunctionVersion640128d35d", - "Version" + "FunctionOneRole", + "Arn" ] }, - "FunctionName": { - "Ref": "MyAwesomeFunction" - }, - "Name": "Live" - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", + "FunctionOneImageBucketPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" + "Ref": "FunctionOne" }, - "SourceArn": { - "Ref": "Notifications" + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionCWEventPermission": { - "Type": "AWS::Lambda::Permission", + "FunctionOneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "FunctionOneImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Fn::If": [ + "MyCondition", + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Ref": "MyAwesomeFunctionAliasLive" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionOne", + "Arn" + ] + } + } + ] + }, + "Tags": [ + { + "Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission", + "Value": { + "Fn::If": [ + "MyCondition", + { + "Ref": "MyAwesomeFunctionS3TriggerPermission" + }, + "no dependency" + ] + } + } + ] + }, + "Type": "AWS::S3::Bucket" + }, + "MyAwesomeFunction": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "SourceArn": { + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "MyAwesomeFunctionCWEvent", + "MyAwesomeFunctionRole", "Arn" ] - } - } + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyAwesomeFunctionEBRulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionAliasLive": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" + "Ref": "MyAwesomeFunction" }, - "SourceArn": { + "FunctionVersion": { "Fn::GetAtt": [ - "MyAwesomeFunctionEBRule", + "MyAwesomeFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "Live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyAwesomeFunctionAnotherSNSWithSQSSubscription": { + "Condition": "MyCondition", + "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", "Arn" ] + }, + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" }, - "MyAwesomeFunctionDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionEventSourceMapping": { "Condition": "MyCondition", "Properties": { - "BatchSize": 200, - "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", + "Arn" + ] + }, "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "LATEST" - } + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionIoTRule": { - "Type": "AWS::IoT::TopicRule", + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue": { + "Condition": "MyCondition", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueuePolicy": { "Condition": "MyCondition", "Properties": { - "TopicRulePayload": { - "AwsIotSqlVersion": "beta", - "Actions": [ + "PolicyDocument": { + "Statement": [ { - "Lambda": { - "FunctionArn": { - "Ref": "MyAwesomeFunctionAliasLive" + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", + "Arn" + ] } } ], - "RuleDisabled": false, - "Sql": "SELECT * FROM 'topic/test'" - } - } + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, - "MyAwesomeFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionCWEvent": { "Condition": "MyCondition", "Properties": { - "BatchSize": 100, - "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } }, - "StartingPosition": "TRIM_HORIZON" - } + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionCWEventLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" }, - "MyAwesomeFunctionIoTRulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionCWEventPermission": { "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" }, + "Principal": "events.amazonaws.com", "SourceArn": { - "Fn::Sub": [ - "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", - { - "RuleName": { - "Ref": "MyAwesomeFunctionIoTRule" - } - } + "Fn::GetAtt": [ + "MyAwesomeFunctionCWEvent", + "Arn" ] } - } - }, - "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", - "Condition": "MyCondition", - "Properties": { - "Endpoint": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Protocol": "lambda", - "TopicArn": { - "Ref": "Notifications" - } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionS3TriggerPermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionCWLog": { "Condition": "MyCondition", + "DependsOn": [ + "MyAwesomeFunctionCWLogPermission" + ], "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { + "DestinationArn": { "Ref": "MyAwesomeFunctionAliasLive" }, - "Principal": "s3.amazonaws.com" - } + "FilterPattern": "My pattern", + "LogGroupName": "MyLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" }, "MyAwesomeFunctionCWLogPermission": { - "Type": "AWS::Lambda::Permission", "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" }, + "Principal": "logs.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", @@ -184,195 +303,178 @@ } ] } - } - }, - "MyAwesomeFunctionEBSchedule": { - "Type": "AWS::Events::Rule", - "Condition": "MyCondition", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "MyAwesomeFunctionEBScheduleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionCWLog": { - "Type": "AWS::Logs::SubscriptionFilter", + "MyAwesomeFunctionDDBStream": { "Condition": "MyCondition", "Properties": { - "DestinationArn": { + "BatchSize": 200, + "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" }, - "FilterPattern": "My pattern", - "LogGroupName": "MyLogGroup" + "StartingPosition": "LATEST" }, - "DependsOn": [ - "MyAwesomeFunctionCWLogPermission" - ] + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", + "MyAwesomeFunctionEBRule": { "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ + "EventPattern": { + "detail": { + "state": [ + "launched" + ] + } + }, + "Targets": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBRuleLambdaTarget" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::Events::Rule" }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", + "MyAwesomeFunctionEBRulePermission": { "Condition": "MyCondition", "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Handler": "hello.handler", - "Role": { + "Principal": "events.amazonaws.com", + "SourceArn": { "Fn::GetAtt": [ - "MyAwesomeFunctionRole", + "MyAwesomeFunctionEBRule", "Arn" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionCWEvent": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionEBSchedule": { "Condition": "MyCondition", "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, + "ScheduleExpression": "rate(1 minute)", "Targets": [ { - "Id": "MyAwesomeFunctionCWEventLambdaTarget", "Arn": { "Ref": "MyAwesomeFunctionAliasLive" - } + }, + "Id": "MyAwesomeFunctionEBScheduleLambdaTarget" } ] - } + }, + "Type": "AWS::Events::Rule" }, - "MyAwesomeFunctionEBRule": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionEBSchedulePermission": { "Condition": "MyCondition", "Properties": { - "EventPattern": { - "detail": { - "state": [ - "launched" - ] - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Targets": [ - { - "Id": "MyAwesomeFunctionEBRuleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionEBSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionIoTRule": { + "Condition": "MyCondition", + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "Lambda": { + "FunctionArn": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } } - } - ] - } + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, + "Sql": "SELECT * FROM 'topic/test'" + } + }, + "Type": "AWS::IoT::TopicRule" }, - "MyAwesomeFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "MyAwesomeFunctionIoTRulePermission": { "Condition": "MyCondition", "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "MyAwesomeFunction" + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + { + "RuleName": { + "Ref": "MyAwesomeFunctionIoTRule" + } + } + ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "Notifications": { + "MyAwesomeFunctionKinesisStream": { "Condition": "MyCondition", - "Type": "AWS::SNS::Topic" + "Properties": { + "BatchSize": 100, + "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionEBSchedulePermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionNotificationTopic": { "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { + "Endpoint": { "Ref": "MyAwesomeFunctionAliasLive" }, - "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionEBSchedule", - "Arn" - ] + "Protocol": "lambda", + "TopicArn": { + "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" }, - "FunctionOneImageBucketPermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionNotificationTopicPermission": { + "Condition": "MyCondition", "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, "FunctionName": { - "Ref": "FunctionOne" + "Ref": "MyAwesomeFunctionAliasLive" }, - "Principal": "s3.amazonaws.com" - } + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" }, - "FunctionOneRole": { - "Type": "AWS::IAM::Role", + "MyAwesomeFunctionRole": { + "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -385,84 +487,40 @@ ] } } - ] - } - } - }, - "FunctionOne": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "FunctionOneRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "Images": { - "Type": "AWS::S3::Bucket", + "MyAwesomeFunctionS3TriggerPermission": { + "Condition": "MyCondition", "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Fn::If": [ - "MyCondition", - { - "Function": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Event": "s3:ObjectCreated:*" - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - { - "Function": { - "Fn::GetAtt": [ - "FunctionOne", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Tags": [ - { - "Key": "sam:ConditionalDependsOn:MyAwesomeFunctionS3TriggerPermission", - "Value": { - "Fn::If": [ - "MyCondition", - { - "Ref": "MyAwesomeFunctionS3TriggerPermission" - }, - "no dependency" - ] - } - } - ] + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } }, - "DependsOn": [ - "FunctionOneImageBucketPermission" - ] + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionSNSTopicWithSQSSubscription": { - "Type": "AWS::SNS::Subscription", + "Condition": "MyCondition", "Properties": { "Endpoint": { "Fn::GetAtt": [ @@ -475,117 +533,32 @@ "Ref": "Notifications" } }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionSNSTopicWithSQSSubscriptionQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", - "Properties": { - "Queues": [ - { - "Ref": "Queue" - } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - }, - "Condition": "MyCondition" + "Type": "AWS::SNS::Subscription" }, "MyAwesomeFunctionSNSTopicWithSQSSubscriptionEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", + "Condition": "MyCondition", "Properties": { "BatchSize": 10, "Enabled": true, - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, "EventSourceArn": { "Fn::GetAtt": [ "Queue", "Arn" ] - } - }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue": { - "Condition": "MyCondition", - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, + }, "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - } - }, - "Condition": "MyCondition" - }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscription": { - "Type": "AWS::SNS::Subscription", - "Properties": { - "Endpoint": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" } }, - "Condition": "MyCondition" + "Type": "AWS::Lambda::EventSourceMapping" }, - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "MyAwesomeFunctionSNSTopicWithSQSSubscriptionQueuePolicy": { + "Condition": "MyCondition", "Properties": { - "Queues": [ - { - "Ref": "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "MyAwesomeFunctionAnotherSNSWithSQSSubscriptionQueue", - "Arn" - ] - }, - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -593,16 +566,43 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + } } - ] + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "Queue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "MyAwesomeFunctionVersion640128d35d": { + "Condition": "MyCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MyAwesomeFunction" } }, - "Condition": "MyCondition" + "Type": "AWS::Lambda::Version" + }, + "Notifications": { + "Condition": "MyCondition", + "Type": "AWS::SNS::Topic" }, "Queue": { - "Type": "AWS::SQS::Queue", - "Condition": "MyCondition" + "Condition": "MyCondition", + "Type": "AWS::SQS::Queue" } } } diff --git a/tests/translator/output/function_managed_inline_policy.json b/tests/translator/output/function_managed_inline_policy.json index a05542ae83..3bf7a149d3 100644 --- a/tests/translator/output/function_managed_inline_policy.json +++ b/tests/translator/output/function_managed_inline_policy.json @@ -1,85 +1,85 @@ { "Parameters": { "SomeManagedPolicyArn": { - "Default": "arn:aws:iam::aws:policy/OtherPolicy", + "Default": "arn:aws:iam::aws:policy/OtherPolicy", "Type": "String" } - }, + }, "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess", - "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess", + "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", { "Ref": "SomeManagedPolicyArn" - }, + }, "arn:aws:iam::123456789012:policy/CustomerCreatedManagedPolicy" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "FunctionRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" + ], + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionRolePolicy0" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_alias.json b/tests/translator/output/function_with_alias.json index 306c5b3870..1017b17817 100644 --- a/tests/translator/output/function_with_alias.json +++ b/tests/translator/output/function_with_alias.json @@ -1,82 +1,82 @@ { "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_alias_and_code_sha256.json b/tests/translator/output/function_with_alias_and_code_sha256.json index 00b2c40f28..0417091f88 100644 --- a/tests/translator/output/function_with_alias_and_code_sha256.json +++ b/tests/translator/output/function_with_alias_and_code_sha256.json @@ -1,14 +1,13 @@ { "Parameters": { "AutoPublishCodeSha256": { - "Type": "String", + "Default": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b", "Description": "Sha256 to uniquely identify creation of the lambda", - "Default": "6b86b273ff34fce19d6b804eff5a3f5747ada4eaa22f1d49c01e52ddb7875b4b" + "Type": "String" } }, "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -28,22 +27,11 @@ "Value": "SAM" } ] - } - }, - "MinimalFunctionVersion6b86b273ff": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } + }, + "Type": "AWS::Lambda::Function" }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { - "Name": "live", "FunctionName": { "Ref": "MinimalFunction" }, @@ -52,14 +40,14 @@ "MinimalFunctionVersion6b86b273ff", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -72,7 +60,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -83,7 +72,18 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion6b86b273ff": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_alias_and_event_sources.json b/tests/translator/output/function_with_alias_and_event_sources.json index eb62f8fae4..574336b382 100644 --- a/tests/translator/output/function_with_alias_and_event_sources.json +++ b/tests/translator/output/function_with_alias_and_event_sources.json @@ -1,169 +1,324 @@ { "Parameters": { "MyStageName": { - "Default": "beta", + "Default": "beta", "Type": "String" } - }, + }, "Resources": { + "GetHtmlApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "webpage_swagger.json" + }, + "Name": "MyGetApi" + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "GetHtmlApiDeploymentf117c932f7": { + "Properties": { + "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "GetHtmlApiStage": { + "Properties": { + "DeploymentId": { + "Ref": "GetHtmlApiDeploymentf117c932f7" + }, + "RestApiId": { + "Ref": "GetHtmlApi" + }, + "StageName": { + "Ref": "MyStageName" + }, + "Variables": { + "LambdaFunction": { + "Ref": "MyAwesomeFunction" + } + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "Images": { + "DependsOn": [ + "MyAwesomeFunctionS3TriggerPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } + ] + } + }, + "Type": "AWS::S3::Bucket" + }, + "MyAwesomeFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyAwesomeFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyAwesomeFunctionAliasLive": { - "Type": "AWS::Lambda::Alias", "Properties": { + "FunctionName": { + "Ref": "MyAwesomeFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MyAwesomeFunctionVersion640128d35d", + "MyAwesomeFunctionVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "MyAwesomeFunction" - }, + }, "Name": "Live" - } - }, - "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Alias" + }, + "MyAwesomeFunctionCWEvent": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionCWEventLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionCWEventPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "events.amazonaws.com", "SourceArn": { - "Ref": "Notifications" + "Fn::GetAtt": [ + "MyAwesomeFunctionCWEvent", + "Arn" + ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment79e6116109" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "GetHtmlApiDeploymentf117c932f7": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionCWLog": { + "DependsOn": [ + "MyAwesomeFunctionCWLogPermission" + ], "Properties": { - "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Description": "RestApi deployment id: f117c932f75cfa87d23dfed64e9430d0081ef289", - "StageName": "Stage" - } - }, - "MyAwesomeFunctionCWEventPermission": { - "Type": "AWS::Lambda::Permission", + "DestinationArn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "FilterPattern": "My pattern", + "LogGroupName": "MyLogGroup" + }, + "Type": "AWS::Logs::SubscriptionFilter" + }, + "MyAwesomeFunctionCWLogPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "logs.amazonaws.com", "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionCWEvent", - "Arn" + "Fn::Sub": [ + "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", + { + "__LogGroupName__": "MyLogGroup" + } ] } - } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionDDBStream": { + "Properties": { + "BatchSize": 200, + "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyAwesomeFunctionEBRule": { + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "launched" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBRuleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" }, "MyAwesomeFunctionEBRulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" }, + "Principal": "events.amazonaws.com", "SourceArn": { "Fn::GetAtt": [ "MyAwesomeFunctionEBRule", "Arn" ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyAwesomeFunctionEBSchedule": { "Properties": { - "BatchSize": 200, - "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Id": "MyAwesomeFunctionEBScheduleLambdaTarget" + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "MyAwesomeFunctionEBSchedulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "LATEST" - } + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyAwesomeFunctionEBSchedule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" }, - "MyAwesomeFunctionIoTRule": { - "Type": "AWS::IoT::TopicRule", + "MyAwesomeFunctionExplicitApiPermissionStage": { "Properties": { - "TopicRulePayload": { - "AwsIotSqlVersion": "beta", - "Actions": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Lambda": { - "FunctionArn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } + "__ApiId__": { + "Ref": "GetHtmlApi" + }, + "__Stage__": "*" } - ], - "RuleDisabled": false, - "Sql": "SELECT * FROM 'topic/test'" + ] } - } - }, - "MyAwesomeFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 100, - "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "StartingPosition": "TRIM_HORIZON" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyAwesomeFunctionImplicitApiPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionIoTRule": { + "Properties": { + "TopicRulePayload": { + "Actions": [ + { + "Lambda": { + "FunctionArn": { + "Ref": "MyAwesomeFunctionAliasLive" + } + } + } + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, + "Sql": "SELECT * FROM 'topic/test'" + } + }, + "Type": "AWS::IoT::TopicRule" + }, "MyAwesomeFunctionIoTRulePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", { "RuleName": { "Ref": "MyAwesomeFunctionIoTRule" @@ -171,306 +326,151 @@ } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "MyAwesomeFunctionKinesisStream": { + "Properties": { + "BatchSize": 100, + "EventSourceArn": "arn:aws:kinesis:us-west-2:012345678901:stream/my-stream", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Ref": "MyAwesomeFunctionAliasLive" - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } - }, - "MyAwesomeFunctionS3TriggerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Principal": "s3.amazonaws.com" - } - }, - "GetHtmlApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "webpage_swagger.json" - }, - "Name": "MyGetApi" - } + }, + "Type": "AWS::SNS::Subscription" }, - "ServerlessRestApiDeployment79e6116109": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 79e6116109d76ade47a8c413291db052ed065647", - "StageName": "Stage" - } - }, - "MyAwesomeFunctionCWLogPermission": { - "Type": "AWS::Lambda::Permission", + "MyAwesomeFunctionNotificationTopicPermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "logs.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "MyAwesomeFunctionAliasLive" - }, + }, + "Principal": "sns.amazonaws.com", "SourceArn": { - "Fn::Sub": [ - "arn:aws:logs:${AWS::Region}:${AWS::AccountId}:log-group:${__LogGroupName__}:*", - { - "__LogGroupName__": "MyLogGroup" - } - ] + "Ref": "Notifications" } - } - }, - "MyAwesomeFunctionEBSchedule": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "Id": "MyAwesomeFunctionEBScheduleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } - }, - "MyAwesomeFunctionCWLog": { - "Type": "AWS::Logs::SubscriptionFilter", - "Properties": { - "DestinationArn": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "FilterPattern": "My pattern", - "LogGroupName": "MyLogGroup" - }, - "DependsOn": [ - "MyAwesomeFunctionCWLogPermission" - ] - }, + }, + "Type": "AWS::Lambda::Permission" + }, "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyAwesomeFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyAwesomeFunctionCWEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "Id": "MyAwesomeFunctionCWEventLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MyAwesomeFunctionEBRule": { - "Type": "AWS::Events::Rule", + "MyAwesomeFunctionS3TriggerPermission": { "Properties": { - "EventPattern": { - "detail": { - "state": [ - "launched" - ] - } + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyAwesomeFunctionAliasLive" }, - "Targets": [ - { - "Id": "MyAwesomeFunctionEBRuleLambdaTarget", - "Arn": { - "Ref": "MyAwesomeFunctionAliasLive" - } - } - ] - } + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MyAwesomeFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "Notifications": { + "Type": "AWS::SNS::Topic" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyAwesomeFunctionAliasLive}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" } - } - }, - "Notifications": { - "Type": "AWS::SNS::Topic" - }, - "MyAwesomeFunctionEBSchedulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "events.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::GetAtt": [ - "MyAwesomeFunctionEBSchedule", - "Arn" - ] - } - } - }, - "Images": { - "Type": "AWS::S3::Bucket", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment79e6116109": { "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "Event": "s3:ObjectCreated:*" - } - ] - } - }, - "DependsOn": [ - "MyAwesomeFunctionS3TriggerPermission" - ] - }, - "GetHtmlApiStage": { - "Type": "AWS::ApiGateway::Stage", + "Description": "RestApi deployment id: 79e6116109d76ade47a8c413291db052ed065647", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "GetHtmlApiDeploymentf117c932f7" - }, + "Ref": "ServerlessRestApiDeployment79e6116109" + }, "RestApiId": { - "Ref": "GetHtmlApi" - }, - "Variables": { - "LambdaFunction": { - "Ref": "MyAwesomeFunction" - } - }, - "StageName": { - "Ref": "MyStageName" - } - } - }, - "MyAwesomeFunctionExplicitApiPermissionStage": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyAwesomeFunctionAliasLive" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "GetHtmlApi" - } - } - ] - } - } + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/function_with_alias_intrinsics.json b/tests/translator/output/function_with_alias_intrinsics.json index 507f8af00b..6cf7e133dd 100644 --- a/tests/translator/output/function_with_alias_intrinsics.json +++ b/tests/translator/output/function_with_alias_intrinsics.json @@ -1,87 +1,87 @@ { "Parameters": { "AliasName": { - "Default": "live", + "Default": "live", "Type": "String" } - }, + }, "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_amq.json b/tests/translator/output/function_with_amq.json index 0d35f71c2a..89472a8189 100644 --- a/tests/translator/output/function_with_amq.json +++ b/tests/translator/output/function_with_amq.json @@ -1,7 +1,6 @@ { "Resources": { "MQFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,30 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MQFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,14 +56,14 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", "PolicyDocument": { "Statement": [ { @@ -65,7 +81,8 @@ "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" } ] - } + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" } ], "Tags": [ @@ -74,25 +91,8 @@ "Value": "SAM" } ] - } - }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_amq_kms.json b/tests/translator/output/function_with_amq_kms.json index 94ae8666a3..1bbcff2f6a 100644 --- a/tests/translator/output/function_with_amq_kms.json +++ b/tests/translator/output/function_with_amq_kms.json @@ -1,105 +1,105 @@ { - "Resources": { - "MQFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "queues.zip" - }, - "Handler": "queue.mq_handler", - "Role": { - "Fn::GetAtt": [ - "MQFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Resources": { + "MQFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "queues.zip" + }, + "Handler": "queue.mq_handler", + "Role": { + "Fn::GetAtt": [ + "MQFunctionRole", + "Arn" ] - } + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MQFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MQFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "mq:DescribeBroker" - ], - "Effect": "Allow", - "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" - } - } + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] } } ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "mq:DescribeBroker" + ], + "Effect": "Allow", + "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" + }, + { + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" + } + } + ] + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" + } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ] - } - } + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/function_with_architectures.json b/tests/translator/output/function_with_architectures.json index 22628a816b..2d6356be60 100644 --- a/tests/translator/output/function_with_architectures.json +++ b/tests/translator/output/function_with_architectures.json @@ -2,20 +2,38 @@ "AWSTemplateFormatVersion": "2010-09-09", "Parameters": {}, "Resources": { - "TestFuncRole": { - "Type": "AWS::IAM::Role", + "TestFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Architectures": [ + "arm64" ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "TestFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "TestFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -28,38 +46,20 @@ ] } } - ] - } - } - }, - "TestFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + ], + "Version": "2012-10-17" }, - "Description": "Created by SAM", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "TestFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x", - "Architectures": [ - "arm64" ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_auth_mechanism_for_self_managed_kafka.json b/tests/translator/output/function_with_auth_mechanism_for_self_managed_kafka.json index 30dea8f779..40ffb27229 100644 --- a/tests/translator/output/function_with_auth_mechanism_for_self_managed_kafka.json +++ b/tests/translator/output/function_with_auth_mechanism_for_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +65,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -70,32 +94,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_condition.json b/tests/translator/output/function_with_condition.json index 25e902d7bc..033cd4b632 100644 --- a/tests/translator/output/function_with_condition.json +++ b/tests/translator/output/function_with_condition.json @@ -2,66 +2,66 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "test", + "test", "test" ] } - }, + }, "Resources": { "ConditionFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "TestCondition", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "ConditionFunctionRole", + "ConditionFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "TestCondition" - }, + }, + "Type": "AWS::Lambda::Function" + }, "ConditionFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "TestCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "TestCondition" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_conditional_managed_policy.json b/tests/translator/output/function_with_conditional_managed_policy.json index db41f277c9..e2c91be6c2 100644 --- a/tests/translator/output/function_with_conditional_managed_policy.json +++ b/tests/translator/output/function_with_conditional_managed_policy.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,12 +22,34 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", { @@ -54,24 +69,9 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_conditional_managed_policy_and_ref_no_value.json b/tests/translator/output/function_with_conditional_managed_policy_and_ref_no_value.json index 2d64091de4..53dcb5f393 100644 --- a/tests/translator/output/function_with_conditional_managed_policy_and_ref_no_value.json +++ b/tests/translator/output/function_with_conditional_managed_policy_and_ref_no_value.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,12 +22,34 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", { @@ -54,24 +69,9 @@ "Key": "lambda:createdBy", "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_conditional_policy_template.json b/tests/translator/output/function_with_conditional_policy_template.json index 9bcd6123e0..7b4b188924 100644 --- a/tests/translator/output/function_with_conditional_policy_template.json +++ b/tests/translator/output/function_with_conditional_policy_template.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,33 +22,49 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithConditionalPolicyRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { "Fn::If": [ "DummyCondition", { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${secretArn}", @@ -63,14 +72,13 @@ "secretArn": "Dummy Secret Arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" }, { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { @@ -80,10 +88,6 @@ "secretsmanager:PutSecretValue", "secretsmanager:UpdateSecretVersionStage" ], - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" - }, - "Effect": "Allow", "Condition": { "StringEquals": { "secretsmanager:resource/AllowRotationLambdaArn": { @@ -95,38 +99,34 @@ ] } } + }, + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*" } }, { "Action": [ "secretsmanager:GetRandomPassword" ], - "Resource": "*", - "Effect": "Allow" + "Effect": "Allow", + "Resource": "*" } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" } ] } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_conditional_policy_template_and_ref_no_value.json b/tests/translator/output/function_with_conditional_policy_template_and_ref_no_value.json index 40262859a5..047f25a49a 100644 --- a/tests/translator/output/function_with_conditional_policy_template_and_ref_no_value.json +++ b/tests/translator/output/function_with_conditional_policy_template_and_ref_no_value.json @@ -9,19 +9,12 @@ }, "Resources": { "FunctionWithConditionalPolicy": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, "Description": "A function that has Fn::If in the policies property", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ @@ -29,33 +22,49 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "FunctionWithConditionalPolicyRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithConditionalPolicyRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { "Fn::If": [ "DummyCondition", { - "PolicyName": "FunctionWithConditionalPolicyRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "secretsmanager:GetSecretValue" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "${secretArn}", @@ -63,11 +72,11 @@ "secretArn": "Dummy Secret Arn" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "FunctionWithConditionalPolicyRolePolicy0" }, { "Ref": "AWS::NoValue" @@ -75,23 +84,14 @@ ] } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json b/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json index 7f9d9822df..8ca6ddeacf 100644 --- a/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json +++ b/tests/translator/output/function_with_custom_codedeploy_deployment_preference.json @@ -1,906 +1,906 @@ { - "Parameters": { - "Deployment": { - "Default": "AllAtOnce", - "Type": "String" - }, - "Custom": { - "Default": "CustomDeployment", - "Type": "String" - }, - "Stage": { - "Default": "beta", - "Type": "String" - } - }, "Conditions": { "MyCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Mappings": { "DeploymentPreferenceMap": { "beta": { "DeploymentPreference": "CustomDeployment" - }, + }, "prod": { "DeploymentPreference": "AllAtOnce" } } - }, + }, + "Parameters": { + "Custom": { + "Default": "CustomDeployment", + "Type": "String" + }, + "Deployment": { + "Default": "AllAtOnce", + "Type": "String" + }, + "Stage": { + "Default": "beta", + "Type": "String" + } + }, "Resources": { - "NormalWithRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "NormalWithRefDeploymentGroup" + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithCondition": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "CustomWithConditionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithCondition2": { "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "CustomWithCondition2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithCondition2Aliaslive": { + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" + }, "FunctionVersion": { "Fn::GetAtt": [ - "NormalWithRefVersion640128d35d", + "CustomWithCondition2Version640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "NormalWithRef" - }, + }, "Name": "live" - } - }, - "CustomWithFindInMapVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithFindInMap" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithCondition2DeploymentGroup" + } } } - }, + }, "CustomWithCondition2DeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "CustomDeployment" ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "CustomWithFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithFindInMapDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "CustomWithFindInMapVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "CustomWithFindInMap" - }, - "Name": "live" - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "CodeDeployServiceRole", "Arn" ] - }, - "Runtime": "python2.7", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithCondition2Role": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithSubAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithSubDeploymentGroup" - } + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithCondition2Version640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition2" } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithConditionAliaslive": { "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + }, "FunctionVersion": { "Fn::GetAtt": [ - "CustomWithSubVersion640128d35d", + "CustomWithConditionVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "CustomWithSub" - }, + }, "Name": "live" - } - }, - "NormalWithSub": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "NormalWithSubRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithConditionDeploymentGroup" } - ] - } - }, - "CustomWithConditionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithCondition" } } - }, - "CustomWithSubDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithConditionDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::If": [ + "MyCondition", + "TestDeploymentConfiguration", + { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": "CustomDeployment" - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "CustomWithCondition2Version640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithCondition2" - } - } - }, - "CustomWithCondition": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithConditionRole": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "CustomWithConditionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithSub": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithConditionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithCondition" + } + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithFindInMap": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "CustomWithSubRole", + "CustomWithFindInMapRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "NormalWithRefVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithFindInMapAliaslive": { "Properties": { "FunctionName": { - "Ref": "NormalWithRef" + "Ref": "CustomWithFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "CustomWithFindInMapVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithFindInMapDeploymentGroup" + } } } - }, - "NormalWithSubDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithFindInMapDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": "CustomDeployment", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithFindInMapRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithFindInMapVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithFindInMap" } - } - }, - "NormalWithRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "Type": "AWS::Lambda::Version" + }, + "CustomWithSub": { "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CustomWithSubRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "NormalWithSubAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "NormalWithSubDeploymentGroup" + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, + ] + }, + "Type": "AWS::Lambda::Function" + }, + "CustomWithSubAliaslive": { "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" + }, "FunctionVersion": { "Fn::GetAtt": [ - "NormalWithSubVersion640128d35d", + "CustomWithSubVersion640128d35d", "Version" ] - }, - "FunctionName": { - "Ref": "NormalWithSub" - }, + }, "Name": "live" - } - }, - "CustomWithSubVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "CustomWithSub" - } - } - }, - "CustomWithSubRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "CustomWithConditionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "CustomWithSubDeploymentGroup" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] } } - }, - "CustomWithConditionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "CustomWithSubDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": "CustomDeployment" + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": { - "Fn::If": [ - "MyCondition", - "TestDeploymentConfiguration", - { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "CustomWithSubRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "CustomWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "CustomWithSub" } - } - }, - "CustomWithFindInMap": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunction": { "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "CustomWithFindInMapRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "NormalWithSubVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { "Properties": { "FunctionName": { - "Ref": "NormalWithSub" - } - } - }, - "CustomWithConditionAliaslive": { - "Type": "AWS::Lambda::Alias", + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { - "Ref": "CustomWithConditionDeploymentGroup" + "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": "TestDeploymentConfiguration", + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "CustomWithConditionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "CustomWithCondition" - }, - "Name": "live" - } - }, - "CustomWithFindInMapRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "NormalWithRef": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "NormalWithRefRole", + "NormalWithRefRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CustomWithCondition2": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "NormalWithRefAliaslive": { "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { + "FunctionName": { + "Ref": "NormalWithRef" + }, + "FunctionVersion": { "Fn::GetAtt": [ - "CustomWithCondition2Role", - "Arn" + "NormalWithRefVersion640128d35d", + "Version" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithRefDeploymentGroup" } - ] + } } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "NormalWithRefDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": "TestDeploymentConfiguration", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" } - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, "NormalWithRefRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "CustomWithCondition2Aliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "CustomWithCondition2DeploymentGroup" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "NormalWithRefVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "NormalWithRef" } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "NormalWithSub": { "Properties": { - "FunctionVersion": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CustomWithCondition2Version640128d35d", - "Version" + "NormalWithSubRole", + "Arn" ] - }, - "FunctionName": { - "Ref": "CustomWithCondition2" - }, - "Name": "live" - } - }, - "NormalWithSubRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "NormalWithSubAliaslive": { "Properties": { "FunctionName": { - "Ref": "MinimalFunction" + "Ref": "NormalWithSub" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "NormalWithSubVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "NormalWithSubDeploymentGroup" + } } } - }, - "CustomWithFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "NormalWithSubDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] - }, - "DeploymentConfigName": "CustomDeployment", - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, - "CustomWithCondition2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "NormalWithSubRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "NormalWithSubVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "NormalWithSub" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json b/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json index 26a20afde3..2f32f0271d 100644 --- a/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json +++ b/tests/translator/output/function_with_custom_conditional_codedeploy_deployment_preference.json @@ -1,199 +1,199 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": { - "EnvType": { - "Default": "dev", - "Type": "String" - } - }, + "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "IsDevEnv2": { + "IsDevEnv": { "Fn::Equals": [ { "Ref": "EnvType" - }, - "prod" + }, + "dev" ] - }, - "IsDevEnv": { + }, + "IsDevEnv2": { "Fn::Equals": [ { "Ref": "EnvType" - }, - "dev" + }, + "prod" ] } - }, + }, + "Parameters": { + "EnvType": { + "Default": "dev", + "Type": "String" + } + }, "Resources": { - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "HelloWorldFunction": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HelloWorldFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "HelloWorldFunctionVersionfb53d5c2e6", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "HelloWorldFunctionDeploymentGroup" + } } } - }, + }, "HelloWorldFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::If": [ - "IsDevEnv", + "IsDevEnv", { "Fn::If": [ - "IsDevEnv2", + "IsDevEnv2", { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "TestCustomDeploymentConfig" ] - }, + }, { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Canary10Percent15Minutes" } ] } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "HelloWorldFunctionVersionfb53d5c2e6": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "HelloWorldFunction" - } - } - }, - "HelloWorldFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "HelloWorldFunctionDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "HelloWorldFunctionVersionfb53d5c2e6", - "Version" - ] - }, - "FunctionName": { - "Ref": "HelloWorldFunction" - }, - "Name": "live" - } - }, - "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Role": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "HelloWorldFunctionRole", + "CodeDeployServiceRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "HelloWorldFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "HelloWorldFunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "HelloWorldFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/function_with_deployment_and_custom_role.json b/tests/translator/output/function_with_deployment_and_custom_role.json index 8ec847d9d0..e3f3f62af6 100644 --- a/tests/translator/output/function_with_deployment_and_custom_role.json +++ b/tests/translator/output/function_with_deployment_and_custom_role.json @@ -1,270 +1,270 @@ { "Resources": { - "FunctionWithRole": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "DeploymentRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "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", + ], + "Effect": "Allow", "Principal": { "Service": [ "codedeploy.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithRole": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "DeploymentRole", + "Arn" ] - } - } - }, - "FunctionWithRoleVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithRoleAliaslive": { "Properties": { "FunctionName": { "Ref": "FunctionWithRole" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FunctionWithRoleVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FunctionWithRoleDeploymentGroup" + } } } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "FunctionWithRoleDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FunctionWithRoleVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FunctionWithRole" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "FunctionWithRoleDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + }, + "MinimalFunctionDeploymentGroup": { "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "AllAtOnce" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } - }, - "FunctionWithRoleAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FunctionWithRoleDeploymentGroup" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionWithRoleVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "FunctionWithRole" - }, - "Name": "live" - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json b/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json index 1a6c407f6a..c670b49561 100644 --- a/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json +++ b/tests/translator/output/function_with_deployment_no_service_role_with_passthrough.json @@ -8,66 +8,9 @@ } }, "Resources": { - "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "Condition1" - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "DeploymentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -76,90 +19,68 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" ] - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "DeploymentRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { "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" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -172,9 +93,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -184,34 +102,62 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "MinimalFunctionRole": { "Properties": { - "ComputePlatform": "Lambda" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunctionVersion640128d35d": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "OtherFunctionRole", @@ -221,39 +167,27 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + "OtherFunctionAliaslive": { + "Condition": "Condition1", "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] }, - "FunctionName": { - "Ref": "MinimalFunction" - }, "Name": "live" - } - }, - "OtherFunctionAliaslive": { + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -264,20 +198,86 @@ "Ref": "OtherFunctionDeploymentGroup" } } - }, + } + }, + "OtherFunctionDeploymentGroup": { "Condition": "Condition1", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", - "Version" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } ] }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "OtherFunctionRole": { + "Condition": "Condition1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "OtherFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "OtherFunction" - }, - "Name": "live" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json b/tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json index e3b229376a..c95941aca6 100644 --- a/tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json +++ b/tests/translator/output/function_with_deployment_no_service_role_without_passthrough.json @@ -8,65 +8,9 @@ } }, "Resources": { - "OtherFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "AllAtOnce" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "DeploymentRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -75,90 +19,68 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRole" ] - } - }, - "OtherFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "OtherFunction" - } }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "OtherFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "DeploymentRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { "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" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -171,9 +93,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Ref": "DeploymentRole" - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -183,34 +102,62 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", + "MinimalFunctionRole": { "Properties": { - "ComputePlatform": "Lambda" - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunctionVersion640128d35d": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" }, "OtherFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "OtherFunctionRole", @@ -220,39 +167,27 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, + "OtherFunctionAliaslive": { + "Condition": "Condition1", "Properties": { + "FunctionName": { + "Ref": "OtherFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "OtherFunctionVersion640128d35d", "Version" ] }, - "FunctionName": { - "Ref": "MinimalFunction" - }, "Name": "live" - } - }, - "OtherFunctionAliaslive": { + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -263,20 +198,85 @@ "Ref": "OtherFunctionDeploymentGroup" } } + } + }, + "OtherFunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "AllAtOnce" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Ref": "DeploymentRole" + } }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "OtherFunctionRole": { "Condition": "Condition1", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "OtherFunctionVersion640128d35d", - "Version" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "OtherFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "OtherFunction" - }, - "Name": "live" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/function_with_deployment_preference.json b/tests/translator/output/function_with_deployment_preference.json index e428000afa..5f092f99d3 100644 --- a/tests/translator/output/function_with_deployment_preference.json +++ b/tests/translator/output/function_with_deployment_preference.json @@ -4,192 +4,192 @@ "Fn::Equals": [ { "Ref": "EnableAliasProvisionedConcurrency" - }, + }, true ] } - }, + }, "Parameters": { "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, + ], + "Default": true, + "Type": "String" + }, "FnName": { "Type": "String" - }, + }, "ProvisionedConcurrency": { - "Default": 10, + "Default": 10, "Type": "String" } - }, + }, "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" } + }, + { + "Ref": "AWS::NoValue" } ] } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "DeploymentGroupName": { "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "Name": "live", - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - }, - { - "Ref": "AWS::NoValue" } - ] + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_preference_alarms_intrinsic_if.json b/tests/translator/output/function_with_deployment_preference_alarms_intrinsic_if.json index 72643d9ca5..ce1a33ffc0 100644 --- a/tests/translator/output/function_with_deployment_preference_alarms_intrinsic_if.json +++ b/tests/translator/output/function_with_deployment_preference_alarms_intrinsic_if.json @@ -8,8 +8,31 @@ } }, "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -29,18 +52,22 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "MinimalFunctionAliaslive": { "Properties": { "FunctionName": { "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -51,88 +78,14 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - } - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "AlarmConfiguration": { "Fn::If": [ "MyCondition", { - "Enabled": true, "Alarms": [ { "Name": "Alarm1" @@ -143,10 +96,10 @@ { "Name": "Alarm3" } - ] + ], + "Enabled": true }, { - "Enabled": true, "Alarms": [ { "Name": "Alarm1" @@ -154,7 +107,8 @@ { "Name": "Alarm5" } - ] + ], + "Enabled": true } ] }, @@ -178,8 +132,8 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, "ServiceRoleArn": { "Fn::GetAtt": [ @@ -187,7 +141,53 @@ "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_preference_all_parameters.json b/tests/translator/output/function_with_deployment_preference_all_parameters.json index aff72299ce..acefb795bf 100644 --- a/tests/translator/output/function_with_deployment_preference_all_parameters.json +++ b/tests/translator/output/function_with_deployment_preference_all_parameters.json @@ -1,138 +1,121 @@ { "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery1Minute" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] }, @@ -142,162 +125,179 @@ "DeploymentSuccess", "DeploymentFailure" ], + "TriggerName": "TestTrigger", "TriggerTargetArn": { "Ref": "MySNSTopic" - }, - "TriggerName": "TestTrigger" + } } ] - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", + "MySanityTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MySNSTopic": { - "Type": "AWS::SNS::Topic" + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json b/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json index 07936044dd..7d08e866d6 100644 --- a/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json +++ b/tests/translator/output/function_with_deployment_preference_condition_with_passthrough.json @@ -17,12 +17,12 @@ }, "Parameters": { "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", "AllowedValues": [ true, false - ] + ], + "Default": true, + "Type": "String" }, "FnName": { "Type": "String" @@ -33,46 +33,10 @@ } }, "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { + "Condition": "FunctionCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -81,32 +45,27 @@ "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "Condition": "FunctionCondition" + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -116,56 +75,40 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition" + "Type": "AWS::Lambda::Function" }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionAliaslive": { + "Condition": "FunctionCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" } + }, + { + "Ref": "AWS::NoValue" } ] } }, - "Condition": "FunctionCondition" - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "FunctionCondition" - }, - "MinimalFunctionAliaslive": { "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { @@ -176,33 +119,90 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Condition": "FunctionCondition", "Properties": { - "Name": "live", - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Ref": "AWS::NoValue" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Condition": "FunctionCondition", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json b/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json index 643c86b29d..d7f3e0c0e4 100644 --- a/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json +++ b/tests/translator/output/function_with_deployment_preference_condition_without_passthrough.json @@ -1,205 +1,205 @@ { - "Conditions": { - "AliasProvisionedConcurrencyEnabled": { - "Fn::Equals": [ - { - "Ref": "EnableAliasProvisionedConcurrency" - }, - true + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] + }, + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "EnableAliasProvisionedConcurrency": { + "AllowedValues": [ + true, + false + ], + "Default": true, + "Type": "String" + }, + "FnName": { + "Type": "String" + }, + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + } + }, + "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "FunctionCondition": { - "Fn::Equals": [ - true, - true - ] - } + "Type": "AWS::IAM::Role" }, - "Parameters": { - "EnableAliasProvisionedConcurrency": { - "Default": true, - "Type": "String", - "AllowedValues": [ - true, - false + "MinimalFunction": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] }, - "FnName": { - "Type": "String" - }, - "ProvisionedConcurrency": { - "Default": 10, - "Type": "String" - } + "Type": "AWS::Lambda::Function" }, - "Resources": { - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { + "MinimalFunctionAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" } } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + } + }, + "MinimalFunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "Condition": "FunctionCondition" - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Value": "SAM", - "Key": "lambda:createdBy" + "ConfigName": "Linear10PercentEvery3Minutes" } ] }, - "Condition": "FunctionCondition" + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "FunctionCondition" + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - } - } - }, - "Condition": "FunctionCondition", - "Properties": { - "Name": "live", - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - } - } - } + "Type": "AWS::CodeDeploy::Application" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/function_with_deployment_preference_from_parameters.json b/tests/translator/output/function_with_deployment_preference_from_parameters.json index bba04a56af..8df5f82638 100644 --- a/tests/translator/output/function_with_deployment_preference_from_parameters.json +++ b/tests/translator/output/function_with_deployment_preference_from_parameters.json @@ -1,152 +1,135 @@ { "Parameters": { - "MyTrueParameter": { - "Default": "True", - "Type": "String" - }, "MyLowerFalseParameter": { "Default": "false", "Type": "String" }, + "MyTrueParameter": { + "Default": "True", + "Type": "String" + }, "MyUpperFalseParameter": { "Default": "False", "Type": "String" } }, "Resources": { - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "CodeDeployServiceRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "codedeploy.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } } } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, + }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery1Minute" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] }, @@ -156,162 +139,179 @@ "DeploymentSuccess", "DeploymentFailure" ], + "TriggerName": "TestTrigger", "TriggerTargetArn": { "Ref": "MySNSTopic" - }, - "TriggerName": "TestTrigger" + } } ] - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySNSTopic": { + "Type": "AWS::SNS::Topic" + }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", + "MySanityTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" - } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MySNSTopic": { - "Type": "AWS::SNS::Topic" + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_preference_multiple_combinations.json b/tests/translator/output/function_with_deployment_preference_multiple_combinations.json index 2ac0953734..0ab6c72018 100644 --- a/tests/translator/output/function_with_deployment_preference_multiple_combinations.json +++ b/tests/translator/output/function_with_deployment_preference_multiple_combinations.json @@ -1,486 +1,486 @@ { "Resources": { - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" ] - } - } - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { - "Type": "AWS::Lambda::Alias", + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, + "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" } } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - }, - "Name": "livewithdeployment" } - }, + }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Linear10PercentEvery2Minutes" } ] - }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, "ServiceRoleArn": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "CodeDeployServiceRole", "Arn" ] } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - } - }, + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "MinimalFunctionWithMinimalDeploymentPreferenceRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { "Properties": { - "Code": { - "S3Bucket": "my-bucket", - "S3Key": "mySanityTestFunction.zip" - }, - "Handler": "hello.handler", - "Role": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { "Fn::GetAtt": [ - "MySanityTestFunctionRole", - "Arn" + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + }, + "Name": "livewithdeployment" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" } - ] - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" } } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } - }, + }, "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" - }, + }, "AutoRollbackConfiguration": { - "Enabled": true, + "Enabled": true, "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", "DEPLOYMENT_STOP_ON_REQUEST" ] - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, + }, "DeploymentConfigName": { "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", + "CodeDeployDefault.Lambda${ConfigName}", { "ConfigName": "Canary10Percent5Minutes" } ] - }, + }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - } - }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } - } - }, - "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" + }, + "MySanityTestFunction": { + "Properties": { + "Code": { + "S3Bucket": "my-bucket", + "S3Key": "mySanityTestFunction.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MySanityTestFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MySanityTestFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } - }, - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - }, - "Name": "livewithdeploymentwithhooksandalarms" - } - }, + ] + }, + "Type": "AWS::IAM::Role" + }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "my-bucket", + "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyValidationTestFunctionRole", + "MyValidationTestFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyValidationTestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json index f908e21bea..44d8c966b2 100644 --- a/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json +++ b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_with_passthrough.json @@ -1,19 +1,9 @@ { "Conditions": { - "ServerlessCodeDeployCondition": { - "Fn::Or": [ - { - "Condition": "Condition2" - }, - { - "Condition": "Condition1" - } - ] - }, - "Condition3": { + "Condition1": { "Fn::Equals": [ true, - false + true ] }, "Condition2": { @@ -22,10 +12,20 @@ false ] }, - "Condition1": { + "Condition3": { "Fn::Equals": [ true, - true + false + ] + }, + "ServerlessCodeDeployCondition": { + "Fn::Or": [ + { + "Condition": "Condition2" + }, + { + "Condition": "Condition1" + } ] } }, @@ -36,38 +36,39 @@ } }, "Resources": { - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "CodeDeployServiceRole": { + "Condition": "ServerlessCodeDeployCondition", "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" ] }, - "Condition": "Condition2" + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MinimalFunctionRole", @@ -77,50 +78,41 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" - }, - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", - "Properties": { - "EvaluationPeriods": 1, - "Namespace": "AWS/EC2", - "Period": 300, - "ComparisonOperator": "GreaterThanThreshold", - "Threshold": 10, - "MetricName": "MyMetric" - } + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionAliaslive": { + "Condition": "Condition1", "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "FunctionName": { + "Ref": "MinimalFunction" }, - "Role": { + "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", - "Arn" + "MinimalFunctionVersion640128d35d", + "Version" ] }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] + "Name": "live" }, - "Condition": "Condition2" + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionDeploymentGroup" + } + } + } }, "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "Condition": "Condition1", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -133,12 +125,6 @@ "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - }, "DeploymentConfigName": { "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", @@ -148,30 +134,22 @@ ] }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } - }, - "Condition": "Condition1" - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] } }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionRole": { + "Condition": "Condition1", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,54 +158,79 @@ "Effect": "Allow", "Principal": { "Service": [ - "codedeploy.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } }, - "Condition": "ServerlessCodeDeployCondition" + "Type": "AWS::Lambda::Version" }, - "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { + "Condition": "Condition2", "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "ServiceRoleArn": { + "Handler": "hello.handler", + "Role": { "Fn::GetAtt": [ - "CodeDeployServiceRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Canary10Percent5Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "Condition2" + "Type": "AWS::Lambda::Function" }, "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Condition": "Condition2", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, @@ -236,92 +239,59 @@ }, "DeploymentGroupName": { "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" } } - }, - "Condition": "Condition2", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - }, - "Name": "livewithdeploymentwithhooksandalarms" } }, - "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { + "Condition": "Condition2", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "AlarmConfiguration": { + "Alarms": [ { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "Name": { + "Ref": "MyCloudWatchAlarm" } } + ], + "Enabled": true + }, + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "ConfigName": "Linear10PercentEvery2Minutes" } ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { + "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -334,53 +304,83 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition1" + "Type": "AWS::IAM::Role" }, - "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithMinimalDeploymentPreference": { + "Condition": "Condition2", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition3" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Condition": "Condition2", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeployment" + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + } + } + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { + "Condition": "Condition2", "Properties": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" @@ -397,23 +397,13 @@ "Fn::Sub": [ "CodeDeployDefault.Lambda${ConfigName}", { - "ConfigName": "Linear10PercentEvery2Minutes" + "ConfigName": "Canary10Percent5Minutes" } ] }, - "AlarmConfiguration": { - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ], - "Enabled": true - }, "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, "ServiceRoleArn": { "Fn::GetAtt": [ @@ -422,23 +412,12 @@ ] } }, - "Condition": "Condition2" - }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - }, - "Condition": "Condition2" + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { + "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -451,54 +430,50 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition2" + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" - } - } - }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { "Condition": "Condition2", + "DeletionPolicy": "Retain", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" - ] - }, "FunctionName": { "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - }, - "Name": "livewithdeployment" - } + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "Condition3", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "my-bucket", "S3Key": "mySanityTestFunction.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MySanityTestFunctionRole", @@ -508,64 +483,51 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "Condition3" - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - }, - "Condition": "ServerlessCodeDeployCondition" + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "MySanityTestFunctionRole": { + "Condition": "Condition3", "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - }, - "Condition": "Condition1" - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "MinimalFunctionDeploymentGroup" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "Condition": "Condition1", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + "Type": "AWS::IAM::Role" }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "my-bucket", "S3Key": "myValidationTestFunction.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyValidationTestFunctionRole", @@ -575,11 +537,49 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyValidationTestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessDeploymentApplication": { + "Condition": "ServerlessCodeDeployCondition", + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json index 0519f0b44e..3a57d86229 100644 --- a/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json +++ b/tests/translator/output/function_with_deployment_preference_multiple_combinations_conditions_without_passthrough.json @@ -21,24 +21,36 @@ }, "Parameters": { "MyFalseParameter": { - "Type": "String", - "Default": false + "Default": false, + "Type": "String" } }, "Resources": { - "MyCloudWatchAlarm": { - "Type": "AWS::CloudWatch::Alarm", + "CodeDeployServiceRole": { "Properties": { - "ComparisonOperator": "GreaterThanThreshold", - "EvaluationPeriods": 1, - "MetricName": "MyMetric", - "Namespace": "AWS/EC2", - "Period": 300, - "Threshold": 10 - } + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Condition": "Condition1", "Properties": { "Code": { @@ -59,21 +71,24 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionAliaslive": { "Condition": "Condition1", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition1", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { @@ -83,26 +98,46 @@ "Ref": "MinimalFunctionDeploymentGroup" } } - }, + } + }, + "MinimalFunctionDeploymentGroup": { "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MinimalFunction" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionVersion": { + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "Condition1", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -115,7 +150,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -126,10 +162,20 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithMinimalDeploymentPreference": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionVersion640128d35d": { + "Condition": "Condition1", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { "Condition": "Condition2", "Properties": { "Code": { @@ -139,7 +185,7 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceRole", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", "Arn" ] }, @@ -150,50 +196,89 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { "Condition": "Condition2", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" - } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeploymentwithhooksandalarms" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition2", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { + "AfterAllowTrafficHook": { + "Ref": "MyValidationTestFunction" + }, "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, + "BeforeAllowTrafficHook": { + "Ref": "MySanityTestFunction" + }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" } } - }, + } + }, + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { "Properties": { - "Name": "livewithdeployment", - "FunctionName": { - "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + "AlarmConfiguration": { + "Alarms": [ + { + "Name": { + "Ref": "MyCloudWatchAlarm" + } + } + ], + "Enabled": true }, - "FunctionVersion": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery2Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithMinimalDeploymentPreferenceRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -206,7 +291,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -217,10 +303,20 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms": { - "Type": "AWS::Lambda::Function", + "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MinimalFunctionWithMinimalDeploymentPreference": { "Condition": "Condition2", "Properties": { "Code": { @@ -230,7 +326,7 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole", + "MinimalFunctionWithMinimalDeploymentPreferenceRole", "Arn" ] }, @@ -241,56 +337,73 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d": { - "Type": "AWS::Lambda::Version", + "MinimalFunctionWithMinimalDeploymentPreferenceAliaslivewithdeployment": { "Condition": "Condition2", - "DeletionPolicy": "Retain", "Properties": { "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" - } - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsAliaslivewithdeploymentwithhooksandalarms": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d", + "Version" + ] + }, + "Name": "livewithdeployment" + }, "Type": "AWS::Lambda::Alias", - "Condition": "Condition2", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, "DeploymentGroupName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup" - }, - "BeforeAllowTrafficHook": { - "Ref": "MySanityTestFunction" - }, - "AfterAllowTrafficHook": { - "Ref": "MyValidationTestFunction" + "Ref": "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup" } } - }, + } + }, + "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { "Properties": { - "Name": "livewithdeploymentwithhooksandalarms", - "FunctionName": { - "Ref": "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarms" + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FunctionVersion": { + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Canary10Percent5Minutes" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { "Fn::GetAtt": [ - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsVersion640128d35d", - "Version" + "CodeDeployServiceRole", + "Arn" ] } - } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsRole": { - "Type": "AWS::IAM::Role", + "MinimalFunctionWithMinimalDeploymentPreferenceRole": { "Condition": "Condition2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -303,7 +416,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -314,10 +428,31 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionWithMinimalDeploymentPreferenceVersion640128d35d": { + "Condition": "Condition2", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunctionWithMinimalDeploymentPreference" + } + }, + "Type": "AWS::Lambda::Version" + }, + "MyCloudWatchAlarm": { + "Properties": { + "ComparisonOperator": "GreaterThanThreshold", + "EvaluationPeriods": 1, + "MetricName": "MyMetric", + "Namespace": "AWS/EC2", + "Period": 300, + "Threshold": 10 + }, + "Type": "AWS::CloudWatch::Alarm" }, "MySanityTestFunction": { - "Type": "AWS::Lambda::Function", "Condition": "Condition3", "Properties": { "Code": { @@ -338,14 +473,13 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MySanityTestFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "Condition3", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -358,7 +492,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -369,10 +504,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MyValidationTestFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "my-bucket", @@ -392,13 +527,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyValidationTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -411,7 +545,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -422,149 +557,14 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", "Properties": { "ComputePlatform": "Lambda" - } - }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] - } - }, - "MinimalFunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery2Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } - }, - "MinimalFunctionWithMinimalDeploymentPreferenceDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Canary10Percent5Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } - }, - "MinimalFunctionWithDeploymentPreferenceWithHooksAndAlarmsDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "AlarmConfiguration": { - "Enabled": true, - "Alarms": [ - { - "Name": { - "Ref": "MyCloudWatchAlarm" - } - } - ] - }, - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery2Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + }, + "Type": "AWS::CodeDeploy::Application" } } } diff --git a/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json b/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json index 9efc3b9c10..151a00187e 100644 --- a/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json +++ b/tests/translator/output/function_with_deployment_preference_passthrough_condition_with_supported_intrinsics.json @@ -1,649 +1,649 @@ { - "Mappings": { - "HelloWorldMap": { - "hello": { - "key1": true, - "key2": false - }, - "world": { - "key1": false, - "key2": true - } - } + "Conditions": { + "AliasProvisionedConcurrencyEnabled": { + "Fn::Equals": [ + { + "Ref": "EnableAliasProvisionedConcurrency" + }, + true + ] }, - "Parameters": { - "FnName": { - "Type": "String" - }, - "ProvisionedConcurrency": { - "Type": "String", - "Default": 10 - }, - "EnableAliasProvisionedConcurrency": { - "Type": "String", - "AllowedValues": [ - true, - false - ], - "Default": true - }, - "DefaultTrueParam": { - "Type": "String", - "Default": "true" - }, - "DefaultFalseParam": { - "Type": "String", - "Default": "false" - }, - "HelloParam": { - "Type": "String", - "Default": "hello" - }, - "WorldParam": { - "Type": "String", - "Default": "world" - } + "FunctionCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Mappings": { + "HelloWorldMap": { + "hello": { + "key1": true, + "key2": false + }, + "world": { + "key1": false, + "key2": true + } + } + }, + "Parameters": { + "DefaultFalseParam": { + "Default": "false", + "Type": "String" }, - "Conditions": { - "AliasProvisionedConcurrencyEnabled": { - "Fn::Equals": [ - { - "Ref": "EnableAliasProvisionedConcurrency" - }, - true - ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - true - ] - } + "DefaultTrueParam": { + "Default": "true", + "Type": "String" + }, + "EnableAliasProvisionedConcurrency": { + "AllowedValues": [ + true, + false + ], + "Default": true, + "Type": "String" + }, + "FnName": { + "Type": "String" + }, + "HelloParam": { + "Default": "hello", + "Type": "String" }, - "Resources": { - "TrueRef": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "TrueRefRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "ProvisionedConcurrency": { + "Default": 10, + "Type": "String" + }, + "WorldParam": { + "Default": "world", + "Type": "String" + } + }, + "Resources": { + "CodeDeployServiceRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "codedeploy.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "TrueRefVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "TrueRef" - } - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseFindInMap": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseFindInMapRole", + "Arn" + ] }, - "TrueRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "TrueRefDeploymentGroup" - } - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FalseFindInMapAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseFindInMapVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "TrueRef" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "TrueRefVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseFindInMapDeploymentGroup" + } + } + } + }, + "FalseFindInMapDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueRefRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "FalseRef": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FalseRefRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FalseFindInMapRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "FalseRefVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "FalseRef" - } - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseFindInMapVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseFindInMap" + } + }, + "Type": "AWS::Lambda::Version" + }, + "FalseRef": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "FalseRefAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FalseRefDeploymentGroup" - } - } + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "FalseRefRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FalseRefAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FalseRefVersion640128d35d", + "Version" + ] + }, + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "FalseRef" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FalseRefVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "FalseRefDeploymentGroup" + } + } + } + }, + "FalseRefDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "FalseRefRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, - "TrueFindInMap": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "TrueFindInMapRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FalseRefRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "TrueFindInMapVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "TrueFindInMap" - } - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FalseRefVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "FalseRef" + } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" + }, + "TrueFindInMap": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueFindInMapRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "TrueFindInMapAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueFindInMapVersion640128d35d", + "Version" + ] }, - "TrueFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "TrueFindInMapDeploymentGroup" - } - } + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "TrueFindInMap" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "TrueFindInMapVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueFindInMapDeploymentGroup" + } + } + } + }, + "TrueFindInMapDeploymentGroup": { + "Condition": "FunctionCondition", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueFindInMapRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "FalseFindInMap": { - "Type": "AWS::Lambda::Function", - "Condition": "FunctionCondition", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FalseFindInMapRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "TrueFindInMapRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" }, - "FalseFindInMapVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "Condition": "FunctionCondition", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "FalseFindInMap" - } - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TrueFindInMapVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueFindInMap" + } + }, + "Type": "AWS::Lambda::Version" + }, + "TrueRef": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "FalseFindInMapAliaslive": { - "Type": "AWS::Lambda::Alias", - "Condition": "FunctionCondition", - "UpdatePolicy": { - "CodeDeployLambdaAliasUpdate": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "DeploymentGroupName": { - "Ref": "FalseFindInMapDeploymentGroup" - } - } - }, - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "FalseFindInMap" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FalseFindInMapVersion640128d35d", - "Version" - ] - }, - "ProvisionedConcurrencyConfig": { - "Fn::If": [ - "AliasProvisionedConcurrencyEnabled", - { - "ProvisionedConcurrentExecutions": { - "Ref": "ProvisionedConcurrency" - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - } + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "TrueRefRole", + "Arn" + ] }, - "FalseFindInMapRole": { - "Type": "AWS::IAM::Role", - "Condition": "FunctionCondition", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "TrueRefAliaslive": { + "Condition": "FunctionCondition", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } + "FunctionVersion": { + "Fn::GetAtt": [ + "TrueRefVersion640128d35d", + "Version" + ] }, - "CodeDeployServiceRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "codedeploy.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSCodeDeployRoleForLambda" - ] + "Name": "live", + "ProvisionedConcurrencyConfig": { + "Fn::If": [ + "AliasProvisionedConcurrencyEnabled", + { + "ProvisionedConcurrentExecutions": { + "Ref": "ProvisionedConcurrency" + } + }, + { + "Ref": "AWS::NoValue" } + ] + } + }, + "Type": "AWS::Lambda::Alias", + "UpdatePolicy": { + "CodeDeployLambdaAliasUpdate": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "DeploymentGroupName": { + "Ref": "TrueRefDeploymentGroup" + } + } + } + }, + "TrueRefDeploymentGroup": { + "Condition": "FunctionCondition", + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" }, - "TrueRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Condition": "FunctionCondition", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] }, - "FalseRefDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery3Minutes" } + ] }, - "TrueFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Condition": "FunctionCondition", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } - } + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" }, - "FalseFindInMapDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", - "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery3Minutes" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::GetAtt": [ - "CodeDeployServiceRole", - "Arn" - ] - } + "ServiceRoleArn": { + "Fn::GetAtt": [ + "CodeDeployServiceRole", + "Arn" + ] + } + }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "TrueRefRole": { + "Condition": "FunctionCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TrueRefVersion640128d35d": { + "Condition": "FunctionCondition", + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "TrueRef" } + }, + "Type": "AWS::Lambda::Version" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/function_with_disabled_deployment_preference.json b/tests/translator/output/function_with_disabled_deployment_preference.json index 47834b6e8f..65750962e1 100644 --- a/tests/translator/output/function_with_disabled_deployment_preference.json +++ b/tests/translator/output/function_with_disabled_deployment_preference.json @@ -1,81 +1,81 @@ { "Resources": { - "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", - "Properties": { - "FunctionName": { - "Ref": "MinimalFunction" - } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } - }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_disabled_traffic_hook.json b/tests/translator/output/function_with_disabled_traffic_hook.json index f9a12a7c22..58326e9d1a 100644 --- a/tests/translator/output/function_with_disabled_traffic_hook.json +++ b/tests/translator/output/function_with_disabled_traffic_hook.json @@ -3,7 +3,6 @@ "Description": "Template with preference that does not require a new CodeDeploy Service Role", "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", @@ -20,59 +19,89 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionVersionfb53d5c2e6": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "FunctionAliaslive": { "Properties": { "FunctionName": { "Ref": "Function" - } - } - }, - "FunctionAliaslive": { + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "FunctionVersionfb53d5c2e6", + "Version" + ] + }, + "Name": "live" + }, "Type": "AWS::Lambda::Alias", "UpdatePolicy": { "CodeDeployLambdaAliasUpdate": { "ApplicationName": { "Ref": "ServerlessDeploymentApplication" }, - "DeploymentGroupName": { - "Ref": "FunctionDeploymentGroup" - }, "BeforeAllowTrafficHook": { "Ref": "preTrafficHook" + }, + "DeploymentGroupName": { + "Ref": "FunctionDeploymentGroup" } } + } + }, + "FunctionDeploymentGroup": { + "Properties": { + "ApplicationName": { + "Ref": "ServerlessDeploymentApplication" + }, + "AutoRollbackConfiguration": { + "Enabled": true, + "Events": [ + "DEPLOYMENT_FAILURE", + "DEPLOYMENT_STOP_ON_ALARM", + "DEPLOYMENT_STOP_ON_REQUEST" + ] + }, + "DeploymentConfigName": { + "Fn::Sub": [ + "CodeDeployDefault.Lambda${ConfigName}", + { + "ConfigName": "Linear10PercentEvery1Minute" + } + ] + }, + "DeploymentStyle": { + "DeploymentOption": "WITH_TRAFFIC_CONTROL", + "DeploymentType": "BLUE_GREEN" + }, + "ServiceRoleArn": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/custom-codedeploy-servicerole" + } }, + "Type": "AWS::CodeDeploy::DeploymentGroup" + }, + "FunctionVersionfb53d5c2e6": { + "DeletionPolicy": "Retain", "Properties": { - "Name": "live", "FunctionName": { "Ref": "Function" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionVersionfb53d5c2e6", - "Version" - ] } - } + }, + "Type": "AWS::Lambda::Version" + }, + "ServerlessDeploymentApplication": { + "Properties": { + "ComputePlatform": "Lambda" + }, + "Type": "AWS::CodeDeploy::Application" }, "preTrafficHook": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "bucket", "S3Key": "key" }, - "FunctionName": "CodeDeployHook_preTrafficHook", - "Handler": "hook.lambda_handler", - "Role": { - "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/lambda-role" - }, - "Runtime": "python3.7", - "Timeout": 5, "Environment": { "Variables": { "NewVersion": { @@ -80,27 +109,24 @@ } } }, + "FunctionName": "CodeDeployHook_preTrafficHook", + "Handler": "hook.lambda_handler", + "Role": { + "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/lambda-role" + }, + "Runtime": "python3.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "preTrafficHookVersion5e9ab26520": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "preTrafficHook" - } - } + ], + "Timeout": 5 + }, + "Type": "AWS::Lambda::Function" }, "preTrafficHookAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { - "Name": "live", "FunctionName": { "Ref": "preTrafficHook" }, @@ -109,45 +135,19 @@ "preTrafficHookVersion5e9ab26520", "Version" ] - } - } - }, - "ServerlessDeploymentApplication": { - "Type": "AWS::CodeDeploy::Application", - "Properties": { - "ComputePlatform": "Lambda" - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "FunctionDeploymentGroup": { - "Type": "AWS::CodeDeploy::DeploymentGroup", + "preTrafficHookVersion5e9ab26520": { + "DeletionPolicy": "Retain", "Properties": { - "ApplicationName": { - "Ref": "ServerlessDeploymentApplication" - }, - "AutoRollbackConfiguration": { - "Enabled": true, - "Events": [ - "DEPLOYMENT_FAILURE", - "DEPLOYMENT_STOP_ON_ALARM", - "DEPLOYMENT_STOP_ON_REQUEST" - ] - }, - "DeploymentConfigName": { - "Fn::Sub": [ - "CodeDeployDefault.Lambda${ConfigName}", - { - "ConfigName": "Linear10PercentEvery1Minute" - } - ] - }, - "DeploymentStyle": { - "DeploymentType": "BLUE_GREEN", - "DeploymentOption": "WITH_TRAFFIC_CONTROL" - }, - "ServiceRoleArn": { - "Fn::Sub": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/custom-codedeploy-servicerole" + "FunctionName": { + "Ref": "preTrafficHook" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_dlq.json b/tests/translator/output/function_with_dlq.json index 599656cd92..d2aa985411 100644 --- a/tests/translator/output/function_with_dlq.json +++ b/tests/translator/output/function_with_dlq.json @@ -1,34 +1,34 @@ { "Resources": { - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "MySnsDlqLambdaFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "DeadLetterConfig": { + "TargetArn": "arn" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MySnsDlqLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": "arn", - "Effect": "Allow" - } - ] - } - } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MySnsDlqLambdaFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -41,62 +41,45 @@ ] } } - ] - } - } - }, - "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": "arn", - "Effect": "Allow" + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": "arn" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "DeadLetterConfig": { + "TargetArn": "arn" + }, "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -104,43 +87,60 @@ "Arn" ] }, - "DeadLetterConfig": { - "TargetArn": "arn" - }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", + "MySqsDlqLambdaFunctionRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySnsDlqLambdaFunctionRole", - "Arn" - ] - }, - "DeadLetterConfig": { - "TargetArn": "arn" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Effect": "Allow", + "Resource": "arn" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" + } + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/function_with_ephemeral_storage.json b/tests/translator/output/function_with_ephemeral_storage.json index 1ad81d4625..8ac8b06394 100644 --- a/tests/translator/output/function_with_ephemeral_storage.json +++ b/tests/translator/output/function_with_ephemeral_storage.json @@ -1,123 +1,123 @@ { + "Parameters": { + "EphemeralStorageSizeRef": { + "Type": "Number" + } + }, "Resources": { "FunctionWithIntrinsicRef": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + }, "EphemeralStorage": { "Size": { "Ref": "EphemeralStorageSizeRef" } - }, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithIntrinsicRefRole", + "FunctionWithIntrinsicRefRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "FunctionWithIntrinsicRefRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "EphemeralStorage": { - "Size": 1024 - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - } - }, - "Parameters": { - "EphemeralStorageSizeRef": { - "Type": "Number" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_event_bridge_rule_state.json b/tests/translator/output/function_with_event_bridge_rule_state.json index 1cfef2294e..4609270e79 100644 --- a/tests/translator/output/function_with_event_bridge_rule_state.json +++ b/tests/translator/output/function_with_event_bridge_rule_state.json @@ -1,118 +1,118 @@ { - "Resources": { - "TestBucket": { - "Type": "AWS::S3::Bucket", - "Properties": { - "BucketName": "test-bucket" - } - }, - "TestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return 'Hello from Lambda!';\n};\n" - }, - "FunctionName": "test-function", - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "TestFunctionRole", - "Arn" - ] + "Resources": { + "TestBucket": { + "Properties": { + "BucketName": "test-bucket" + }, + "Type": "AWS::S3::Bucket" }, - "Runtime": "nodejs16.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "TestFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "TestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return 'Hello from Lambda!';\n};\n" + }, + "FunctionName": "test-function", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "TestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs16.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] - } - } - ] + }, + "Type": "AWS::Lambda::Function" }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "TestFunctionTestEventBridgeRule": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "source": [ - "aws.s3" - ], - "detail-type": [ - "Object Created" - ], - "detail": { - "bucket": { - "name": [ - "test-bucket" - ] + "TestFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "object": { - "key": [ - { - "prefix": "/" - } - ] - } - } + "Type": "AWS::IAM::Role" }, - "State": "ENABLED", - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "TestFunction", - "Arn" - ] + "TestFunctionTestEventBridgeRule": { + "Properties": { + "EventPattern": { + "detail": { + "bucket": { + "name": [ + "test-bucket" + ] + }, + "object": { + "key": [ + { + "prefix": "/" + } + ] + } + }, + "detail-type": [ + "Object Created" + ], + "source": [ + "aws.s3" + ] + }, + "State": "ENABLED", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "TestFunction", + "Arn" + ] + }, + "Id": "TestFunctionTestEventBridgeRuleLambdaTarget" + } + ] }, - "Id": "TestFunctionTestEventBridgeRuleLambdaTarget" - } - ] - } - }, - "TestFunctionTestEventBridgeRulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "TestFunction" + "Type": "AWS::Events::Rule" }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "TestFunctionTestEventBridgeRule", - "Arn" - ] + "TestFunctionTestEventBridgeRulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "TestFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "TestFunctionTestEventBridgeRule", + "Arn" + ] + } + }, + "Type": "AWS::Lambda::Permission" } - } } - } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_event_dest.json b/tests/translator/output/function_with_event_dest.json index f75a3bfa36..6031ba98e2 100644 --- a/tests/translator/output/function_with_event_dest.json +++ b/tests/translator/output/function_with_event_dest.json @@ -1,369 +1,369 @@ { "Conditions": { - "TopicCreationEnabled": { - "Fn::Equals": [ - { - "Ref": "CreateSNSTopic" - }, - true - ] - }, "NOTQueueCreationDisabled2da03e5b6f": { "Fn::Not": [ { "Condition": "QueueCreationDisabled" } ] - }, + }, "QueueCreationDisabled": { "Fn::Equals": [ { "Ref": "UseExistingQueue" - }, + }, + true + ] + }, + "TopicCreationEnabled": { + "Fn::Equals": [ + { + "Ref": "CreateSNSTopic" + }, true ] } - }, + }, "Parameters": { - "UseExistingQueue": { - "Default": true, - "Type": "String", - "AllowedValues": [ - true, - false - ] - }, "CreateSNSTopic": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, + ], + "Default": true, + "Type": "String" + }, "SQSArn": { - "Default": "my-sqs-arn", + "Default": "my-sqs-arn", + "Type": "String" + }, + "UseExistingQueue": { + "AllowedValues": [ + true, + false + ], + "Default": true, "Type": "String" } - }, + }, "Resources": { - "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", + "DestinationLambda": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "DestinationLambdaRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "DestinationLambdaRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ - { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", - { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - }, - "my-sqs-arn" - ] - }, - "Effect": "Allow" - } - ] - } - }, + ], + "Tags": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "sns:publish", - "Resource": { - "Fn::If": [ - "TopicCreationEnabled", - { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - }, - "SOME-SNS-ARN" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {}, - "Condition": "NOTQueueCreationDisabled2da03e5b6f" - }, - "SNSSubscription": { - "Type": "AWS::SNS::Subscription", + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunction2": { "Properties": { - "Endpoint": "example@example.com", - "Protocol": "email", - "TopicArn": { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - } - }, - "Condition": "TopicCreationEnabled" - }, - "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunction2EventInvokeConfig": { "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { - "OnSuccess": { - "Destination": { - "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", - { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - }, - "my-sqs-arn" - ] - } - }, "OnFailure": { + "Destination": "event-bus-arn" + }, + "OnSuccess": { "Destination": { - "Fn::If": [ - "TopicCreationEnabled", - { - "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" - }, - "SOME-SNS-ARN" + "Fn::GetAtt": [ + "DestinationLambda", + "Arn" ] } } - }, + }, "FunctionName": { - "Ref": "MyTestFunction" - }, + "Ref": "MyTestFunction2" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - } - }, + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, "MyTestFunction2Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunction2EventInvokeConfigOnSuccessLambdaPolicy", "PolicyDocument": { "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "DestinationLambda", + "DestinationLambda", "Arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunction2EventInvokeConfigOnSuccessLambdaPolicy" + }, { - "PolicyName": "MyTestFunction2EventInvokeConfigOnFailureEventBridgePolicy", "PolicyDocument": { "Statement": [ { - "Action": "events:PutEvents", - "Resource": "event-bus-arn", - "Effect": "Allow" + "Action": "events:PutEvents", + "Effect": "Allow", + "Resource": "event-bus-arn" } ] - } + }, + "PolicyName": "MyTestFunction2EventInvokeConfigOnFailureEventBridgePolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "DestinationLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "DestinationLambdaRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunction2EventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunctionEventInvokeConfig": { "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { + "OnFailure": { + "Destination": { + "Fn::If": [ + "TopicCreationEnabled", + { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + }, + "SOME-SNS-ARN" + ] + } + }, "OnSuccess": { "Destination": { - "Fn::GetAtt": [ - "DestinationLambda", - "Arn" + "Fn::If": [ + "NOTQueueCreationDisabled2da03e5b6f", + { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + }, + "my-sqs-arn" ] } - }, - "OnFailure": { - "Destination": "event-bus-arn" } - }, + }, "FunctionName": { - "Ref": "MyTestFunction2" - }, + "Ref": "MyTestFunction" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - } - }, - "DestinationLambdaRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, + "MyTestFunctionEventInvokeConfigOnFailureTopic": { + "Condition": "TopicCreationEnabled", + "Properties": {}, + "Type": "AWS::SNS::Topic" + }, + "MyTestFunctionEventInvokeConfigOnSuccessQueue": { + "Condition": "NOTQueueCreationDisabled2da03e5b6f", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "MyTestFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyTestFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Effect": "Allow", + "Resource": { + "Fn::If": [ + "NOTQueueCreationDisabled2da03e5b6f", + { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + }, + "my-sqs-arn" + ] + } + } + ] + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:publish", + "Effect": "Allow", + "Resource": { + "Fn::If": [ + "TopicCreationEnabled", + { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + }, + "SOME-SNS-ARN" + ] + } + } + ] + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunctionEventInvokeConfigOnFailureTopic": { - "Type": "AWS::SNS::Topic", - "Properties": {}, - "Condition": "TopicCreationEnabled" + ] + }, + "Type": "AWS::IAM::Role" + }, + "SNSSubscription": { + "Condition": "TopicCreationEnabled", + "Properties": { + "Endpoint": "example@example.com", + "Protocol": "email", + "TopicArn": { + "Ref": "MyTestFunctionEventInvokeConfigOnFailureTopic" + } + }, + "Type": "AWS::SNS::Subscription" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_event_dest_basic.json b/tests/translator/output/function_with_event_dest_basic.json index e845f151f5..ccba565556 100644 --- a/tests/translator/output/function_with_event_dest_basic.json +++ b/tests/translator/output/function_with_event_dest_basic.json @@ -1,149 +1,149 @@ { "Parameters": { "SNSArn": { - "Default": "my-sns-arn", + "Default": "my-sns-arn", "Type": "String" } - }, + }, "Resources": { + "MyTestFunction": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyTestFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MyTestFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MyTestFunctionVersiondaf9da458d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyTestFunctionEventInvokeConfig": { + "DependsOn": [ + "MyTestFunctionAliaslive" + ], + "Properties": { + "DestinationConfig": { + "OnFailure": { + "Destination": "my-sns-arn" + }, + "OnSuccess": { + "Destination": { + "Fn::GetAtt": [ + "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "Arn" + ] + } + } + }, + "FunctionName": { + "Ref": "MyTestFunction" + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, + "Qualifier": "live" + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sns:publish", - "Resource": "my-sns-arn", - "Effect": "Allow" + "Action": "sns:publish", + "Effect": "Allow", + "Resource": "my-sns-arn" } ] - } + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureSNSPolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", - "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, - "DestinationConfig": { - "OnSuccess": { - "Destination": { - "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", - "Arn" - ] - } - }, - "OnFailure": { - "Destination": "my-sns-arn" - } - }, - "FunctionName": { - "Ref": "MyTestFunction" - }, - "Qualifier": "live" - }, - "DependsOn": [ - "MyTestFunctionAliaslive" - ] - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - }, - "MyTestFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MyTestFunctionVersiondaf9da458d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MyTestFunction" - }, - "Name": "live" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "MyTestFunctionVersiondaf9da458d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MyTestFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_event_dest_conditional.json b/tests/translator/output/function_with_event_dest_conditional.json index 8706ccf9f6..9d31a33fca 100644 --- a/tests/translator/output/function_with_event_dest_conditional.json +++ b/tests/translator/output/function_with_event_dest_conditional.json @@ -1,266 +1,266 @@ { "Conditions": { + "FunctionCondition": { + "Fn::Equals": [ + true, + false + ] + }, "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6": { "Fn::And": [ { "Condition": { "Condition": "FunctionCondition" } - }, + }, { "Condition": { "Condition": "NOTQueueCreationDisabled2da03e5b6f" } } ] - }, - "QueueCreationDisabled": { + }, + "FunctionInlineEnabled": { "Fn::Equals": [ - { - "Ref": "UseExistingQueue" - }, - true + true, + false ] - }, + }, "NOTQueueCreationDisabled2da03e5b6f": { "Fn::Not": [ { "Condition": "QueueCreationDisabled" } ] - }, - "FunctionCondition": { - "Fn::Equals": [ - true, - false - ] - }, - "FunctionInlineEnabled": { + }, + "QueueCreationDisabled": { "Fn::Equals": [ - true, - false + { + "Ref": "UseExistingQueue" + }, + true ] } - }, + }, "Parameters": { + "SQSArn": { + "Default": "my-sqs-arn", + "Type": "String" + }, "UseExistingQueue": { - "Default": true, - "Type": "String", "AllowedValues": [ - true, + true, false - ] - }, - "SQSArn": { - "Default": "my-sqs-arn", + ], + "Default": true, "Type": "String" } - }, + }, "Resources": { + "DestinationLambda": { + "Condition": "FunctionInlineEnabled", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "DestinationLambdaRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "DestinationLambdaRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionInlineEnabled", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionInlineEnabled" - }, - "MyTestFunctionEventInvokeConfigOnSuccessQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {}, - "Condition": "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6" - }, + }, + "Type": "AWS::IAM::Role" + }, + "MyTestFunction": { + "Condition": "FunctionCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" + }, + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyTestFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyTestFunctionEventInvokeConfig": { - "Type": "AWS::Lambda::EventInvokeConfig", + "Condition": "FunctionCondition", "Properties": { - "MaximumEventAgeInSeconds": 70, - "MaximumRetryAttempts": 1, "DestinationConfig": { - "OnSuccess": { + "OnFailure": { "Destination": { "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", + "FunctionInlineEnabled", { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "DestinationLambda", "Arn" ] - }, - "my-sqs-arn" + }, + "some-function-arn" ] } - }, - "OnFailure": { + }, + "OnSuccess": { "Destination": { "Fn::If": [ - "FunctionInlineEnabled", + "NOTQueueCreationDisabled2da03e5b6f", { "Fn::GetAtt": [ - "DestinationLambda", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, - "some-function-arn" + }, + "my-sqs-arn" ] } } - }, + }, "FunctionName": { "Ref": "MyTestFunction" - }, + }, + "MaximumEventAgeInSeconds": 70, + "MaximumRetryAttempts": 1, "Qualifier": "$LATEST" - }, - "Condition": "FunctionCondition" - }, - "MyTestFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = function(event, context, callback) {\n var event_received_at = new Date().toISOString();\n console.log('Event received at: ' + event_received_at);\n console.log('Received event:', JSON.stringify(event, null, 2));\n\n if (event.Success) {\n console.log(\"Success\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(null);\n } else {\n console.log(\"Failure\");\n context.callbackWaitsForEmptyEventLoop = false;\n callback(new Error(\"Failure from event, Success = false, I am failing!\"), 'Destination Function Error Thrown');\n }\n}; \n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyTestFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "Condition": "FunctionCondition" - }, - "DestinationLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "DestinationLambdaRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - }, - "Condition": "FunctionInlineEnabled" - }, + }, + "Type": "AWS::Lambda::EventInvokeConfig" + }, + "MyTestFunctionEventInvokeConfigOnSuccessQueue": { + "Condition": "FunctionConditionANDNOTQueueCreationDisabled2da03e5b6fe547d4e2d6", + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, "MyTestFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Policies": [ { - "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy", "PolicyDocument": { "Statement": [ { - "Action": "sqs:SendMessage", + "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::If": [ - "NOTQueueCreationDisabled2da03e5b6f", + "NOTQueueCreationDisabled2da03e5b6f", { "Fn::GetAtt": [ - "MyTestFunctionEventInvokeConfigOnSuccessQueue", + "MyTestFunctionEventInvokeConfigOnSuccessQueue", "Arn" ] - }, + }, "my-sqs-arn" ] - }, - "Effect": "Allow" + } } ] - } - }, + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnSuccessSQSPolicy" + }, { - "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureLambdaPolicy", "PolicyDocument": { "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::If": [ - "FunctionInlineEnabled", + "FunctionInlineEnabled", { "Fn::GetAtt": [ - "DestinationLambda", + "DestinationLambda", "Arn" ] - }, + }, "some-function-arn" ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MyTestFunctionEventInvokeConfigOnFailureLambdaPolicy" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "FunctionCondition" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_event_filtering.json b/tests/translator/output/function_with_event_filtering.json index 688dbd489b..8be1874447 100644 --- a/tests/translator/output/function_with_event_filtering.json +++ b/tests/translator/output/function_with_event_filtering.json @@ -1,19 +1,9 @@ { "Resources": { - "KinesisStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } - }, "DynamoDBTable": { "Type": "AWS::DynamoDB::Table" }, - "MySqsQueue": { - "Type": "AWS::SQS::Queue" - }, "FilteredEventsFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -33,101 +23,10 @@ "Value": "SAM" } ] - } - }, - "FilteredEventsFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Policies": [ - { - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "ec2:CreateNetworkInterface", - "ec2:DescribeNetworkInterfaces", - "ec2:DeleteNetworkInterface", - "ec2:DescribeVpcs", - "ec2:DescribeSubnets", - "ec2:DescribeSecurityGroups" - ], - "Effect": "Allow", - "Resource": "*" - } - ], - "Version": "2012-10-17" - }, - "PolicyName": "SelfManagedKafkaExecutionRolePolicy" - }, - { - "PolicyName": "SamAutoGeneratedAMQPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "secretsmanager:GetSecretValue" - ], - "Effect": "Allow", - "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Action": [ - "mq:DescribeBroker" - ], - "Effect": "Allow", - "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" - }, - { - "Action": "kms:Decrypt", - "Effect": "Allow", - "Resource": { - "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" - } - } - ] - } - } - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "FilteredEventsFunctionDynamoDBStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": { "Fn::GetAtt": [ @@ -135,21 +34,21 @@ "StreamArn" ] }, - "FunctionName": { - "Ref": "FilteredEventsFunction" - }, - "StartingPosition": "TRIM_HORIZON", "FilterCriteria": { "Filters": [ { "Pattern": "{ \"dynamodb\": { \"NewImage\": { \"value\": { \"S\": [\"test\"] } } } }" } ] - } - } + }, + "FunctionName": { + "Ref": "FilteredEventsFunction" + }, + "StartingPosition": "TRIM_HORIZON" + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "FilteredEventsFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": { "Fn::GetAtt": [ @@ -157,10 +56,6 @@ "Arn" ] }, - "FunctionName": { - "Ref": "FilteredEventsFunction" - }, - "StartingPosition": "LATEST", "FilterCriteria": { "Filters": [ { @@ -170,59 +65,53 @@ "Pattern": "{\"name2\": \"value2\"}" } ] - } - } - }, - "FilteredEventsFunctionMySqsEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Fn::GetAtt": [ - "MySqsQueue", - "Arn" - ] }, "FunctionName": { "Ref": "FilteredEventsFunction" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMSKEvent": { + "Properties": { + "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMSKEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, "StartingPosition": "LATEST", "Topics": [ "MyDummyTestTopic" - ], + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMyKafkaEvent": { + "Properties": { "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMyKafkaEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, - "Topics": [ - "Topic1" - ], + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092" + ] + } + }, "SourceAccessConfigurations": [ { "Type": "SASL_SCRAM_512_AUTH", @@ -237,26 +126,22 @@ "URI": "security_group:sg-67890" } ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092" - ] - } - }, + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] - } - } - }, - "FilteredEventsFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + }, "FunctionName": { "Ref": "FilteredEventsFunction" }, @@ -268,15 +153,130 @@ "Type": "BASIC_AUTH", "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" } - ], + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionMySqsEvent": { + "Properties": { + "EventSourceArn": { + "Fn::GetAtt": [ + "MySqsQueue", + "Arn" + ] + }, "FilterCriteria": { "Filters": [ { "Pattern": "{\"name\": \"value\"}" } ] + }, + "FunctionName": { + "Ref": "FilteredEventsFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "FilteredEventsFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "ec2:CreateNetworkInterface", + "ec2:DescribeNetworkInterfaces", + "ec2:DeleteNetworkInterface", + "ec2:DescribeVpcs", + "ec2:DescribeSubnets", + "ec2:DescribeSecurityGroups" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "SelfManagedKafkaExecutionRolePolicy" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "secretsmanager:GetSecretValue" + ], + "Effect": "Allow", + "Resource": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Action": [ + "mq:DescribeBroker" + ], + "Effect": "Allow", + "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" + }, + { + "Action": "kms:Decrypt", + "Effect": "Allow", + "Resource": { + "Fn::Sub": "arn:${AWS::Partition}:kms:${AWS::Region}:${AWS::AccountId}:key/1abc23d4-567f-8ab9-cde0-1fab234c5d67" + } + } + ] + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" + } + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "KinesisStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "MySqsQueue": { + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_event_schedule_state.json b/tests/translator/output/function_with_event_schedule_state.json index 04f1131b6e..060ffafbdf 100644 --- a/tests/translator/output/function_with_event_schedule_state.json +++ b/tests/translator/output/function_with_event_schedule_state.json @@ -1,176 +1,176 @@ { - "Parameters": { - "ScheduleState": { - "Type": "String", - "Default": "Disabled" - } - }, - "Resources": { - "ScheduledFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip", - "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ScheduledFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.10", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "ScheduledFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Parameters": { + "ScheduleState": { + "Default": "Disabled", + "Type": "String" + } + }, + "Resources": { + "ScheduledFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip", + "S3ObjectVersion": "3Tcgv52_0GaDvhDva4YciYeqRyPnpIcO" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "ScheduledFunctionRole", + "Arn" ] - } + }, + "Runtime": "python3.10", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "ScheduledFunctionSchedule1": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": "Enabled", - "Targets": [ + "Type": "AWS::Lambda::Function" + }, + "ScheduledFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] - }, - "Id": "ScheduledFunctionSchedule1LambdaTarget" + } } - ] - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "ScheduledFunctionSchedule1Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule1", - "Arn" - ] + "Type": "AWS::IAM::Role" + }, + "ScheduledFunctionSchedule1": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": "Enabled", + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule1LambdaTarget" } - } + ] }, - "ScheduledFunctionSchedule2": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": { - "Fn::Sub": "Enabled" - }, - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - }, - "Id": "ScheduledFunctionSchedule2LambdaTarget" - } + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule1Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule1", + "Arn" ] } }, - "ScheduledFunctionSchedule2Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule2", - "Arn" - ] + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionSchedule2": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": { + "Fn::Sub": "Enabled" + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule2LambdaTarget" } - } + ] }, - "ScheduledFunctionSchedule3": { - "Type": "AWS::Events::Rule", - "Properties": { - "Description": "Test Schedule", - "Name": "test-schedule", - "ScheduleExpression": "rate(1 minute)", - "State": { - "Ref": "ScheduleState" - }, - "Targets": [ - { - "Arn": { - "Fn::GetAtt": [ - "ScheduledFunction", - "Arn" - ] - }, - "Id": "ScheduledFunctionSchedule3LambdaTarget" - } + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule2Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule2", + "Arn" ] } }, - "ScheduledFunctionSchedule3Permission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "ScheduledFunction" - }, - "Principal": "events.amazonaws.com", - "SourceArn": { - "Fn::GetAtt": [ - "ScheduledFunctionSchedule3", - "Arn" - ] + "Type": "AWS::Lambda::Permission" + }, + "ScheduledFunctionSchedule3": { + "Properties": { + "Description": "Test Schedule", + "Name": "test-schedule", + "ScheduleExpression": "rate(1 minute)", + "State": { + "Ref": "ScheduleState" + }, + "Targets": [ + { + "Arn": { + "Fn::GetAtt": [ + "ScheduledFunction", + "Arn" + ] + }, + "Id": "ScheduledFunctionSchedule3LambdaTarget" } + ] + }, + "Type": "AWS::Events::Rule" + }, + "ScheduledFunctionSchedule3Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ScheduledFunction" + }, + "Principal": "events.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "ScheduledFunctionSchedule3", + "Arn" + ] } - } + }, + "Type": "AWS::Lambda::Permission" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/function_with_event_source_mapping.json b/tests/translator/output/function_with_event_source_mapping.json index fcff5cabc5..9789832639 100644 --- a/tests/translator/output/function_with_event_source_mapping.json +++ b/tests/translator/output/function_with_event_source_mapping.json @@ -3,60 +3,124 @@ "Parameters": { "MyBatchingWindowParam": { "Default": 45, - "Type": "Number", - "Description": "parameter for batching window in seconds" + "Description": "parameter for batching window in seconds", + "Type": "Number" } }, "Resources": { - "MySqsQueue": { - "Type": "AWS::SQS::Queue" - }, - "MySnsTopic": { - "Type": "AWS::SNS::Topic" - }, - "MyFunctionForBatchingExampleStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": 20, - "EventSourceArn": { - "Fn::GetAtt": [ - "KinesisStream", - "Arn" - ] - }, - "FunctionName": { - "Ref": "MyFunctionForBatchingExample" - }, - "StartingPosition": "LATEST" - } - }, "DynamoDBTable": { - "Type": "AWS::DynamoDB::Table", "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ], + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 + }, "StreamSpecification": { "StreamViewType": "NEW_IMAGE" + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "KinesisStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "KinesisStream1": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" + }, + "MyFunctionForBatchingExample": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" }, - "AttributeDefinitions": [ + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunctionForBatchingExampleRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "AttributeName": "id", - "AttributeType": "S" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionForBatchingExampleDynamoDBStreamEvent": { + "Properties": { + "BatchSize": 100, + "BisectBatchOnFunctionError": true, + "DestinationConfig": { + "OnFailure": { + "Destination": { + "Fn::GetAtt": [ + "MySqsQueue", + "Arn" + ] + } + } + }, + "EventSourceArn": { + "Fn::GetAtt": [ + "DynamoDBTable", + "StreamArn" + ] + }, + "FunctionName": { + "Ref": "MyFunctionForBatchingExample" + }, + "FunctionResponseTypes": [ + "ReportBatchItemFailures" ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } + "MaximumBatchingWindowInSeconds": { + "Ref": "MyBatchingWindowParam" + }, + "MaximumRecordAgeInSeconds": 86400, + "MaximumRetryAttempts": 100, + "ParallelizationFactor": 8, + "StartingPosition": "TRIM_HORIZON", + "TumblingWindowInSeconds": 60 + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyFunctionForBatchingExampleRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole", @@ -64,13 +128,13 @@ ], "Policies": [ { - "PolicyName": "MyFunctionForBatchingExampleRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -83,14 +147,13 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MyFunctionForBatchingExampleRolePolicy0" }, { - "PolicyName": "MyFunctionForBatchingExampleDynamoDBStreamEventSQSPolicy", "PolicyDocument": { "Statement": [ { @@ -104,116 +167,58 @@ } } ] - } + }, + "PolicyName": "MyFunctionForBatchingExampleDynamoDBStreamEventSQSPolicy" }, { "PolicyDocument": { - "Statement": [ - { - "Action": "sns:publish", - "Effect": "Allow", - "Resource": { - "Ref": "MySnsTopic" - } - } - ] + "Statement": [ + { + "Action": "sns:publish", + "Effect": "Allow", + "Resource": { + "Ref": "MySnsTopic" + } + } + ] }, "PolicyName": "MyFunctionForBatchingExampleStreamEventSNSPolicy" } ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "KinesisStream1": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyFunctionForBatchingExampleDynamoDBStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", + "MyFunctionForBatchingExampleStream": { "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "MyBatchingWindowParam" + "EventSourceArn": { + "Fn::GetAtt": [ + "KinesisStream", + "Arn" + ] }, "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "MaximumRecordAgeInSeconds": 86400, - "BatchSize": 100, + "MaximumBatchingWindowInSeconds": 20, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEvent": { + "Properties": { "DestinationConfig": { "OnFailure": { "Destination": { - "Fn::GetAtt": [ - "MySqsQueue", - "Arn" - ] + "Ref": "MySnsTopic" } } }, - "EventSourceArn": { - "Fn::GetAtt": [ - "DynamoDBTable", - "StreamArn" - ] - }, - "StartingPosition": "TRIM_HORIZON", - "ParallelizationFactor": 8, - "MaximumRetryAttempts": 100, - "BisectBatchOnFunctionError": true, - "TumblingWindowInSeconds": 60, - "FunctionResponseTypes": ["ReportBatchItemFailures"] - } - }, - "MyFunctionForBatchingExample": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "ZipFile": "exports.handler = async (event) => {\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionForBatchingExampleRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyFunctionForBatchingExampleStreamEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "MyBatchingWindowParam" - }, "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -223,22 +228,15 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "StartingPosition": "LATEST", - "DestinationConfig": { - "OnFailure": { - "Destination": { - "Ref": "MySnsTopic" - } - } - } - } - }, - "MyFunctionForBatchingExampleStreamEventWithoutDestinationConfigType": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { "MaximumBatchingWindowInSeconds": { "Ref": "MyBatchingWindowParam" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEventWithEmptyDestinationConfig": { + "Properties": { "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -248,22 +246,22 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, - "StartingPosition": "LATEST", - "DestinationConfig": { - "OnFailure": { - "Destination": { - "Ref": "MySnsTopic" - } - } - } - } - }, - "MyFunctionForBatchingExampleStreamEventWithEmptyDestinationConfig": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { "MaximumBatchingWindowInSeconds": { "Ref": "MyBatchingWindowParam" }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyFunctionForBatchingExampleStreamEventWithoutDestinationConfigType": { + "Properties": { + "DestinationConfig": { + "OnFailure": { + "Destination": { + "Ref": "MySnsTopic" + } + } + }, "EventSourceArn": { "Fn::GetAtt": [ "KinesisStream1", @@ -273,14 +271,18 @@ "FunctionName": { "Ref": "MyFunctionForBatchingExample" }, + "MaximumBatchingWindowInSeconds": { + "Ref": "MyBatchingWindowParam" + }, "StartingPosition": "LATEST" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "KinesisStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } + "MySnsTopic": { + "Type": "AWS::SNS::Topic" + }, + "MySqsQueue": { + "Type": "AWS::SQS::Queue" } } } diff --git a/tests/translator/output/function_with_file_system_config.json b/tests/translator/output/function_with_file_system_config.json index b9bbcccdc9..f6e8c166c5 100644 --- a/tests/translator/output/function_with_file_system_config.json +++ b/tests/translator/output/function_with_file_system_config.json @@ -1,115 +1,115 @@ { + "Description": "SAM + Lambda + EFS", + "Parameters": { + "ExistingEfsFileSystem": { + "Type": "String" + }, + "SecurityGroupIds": { + "Description": "Security Group IDs that Lambda will use", + "Type": "List" + }, + "VpcSubnetIds": { + "Description": "VPC Subnet IDs that Lambda will use", + "Type": "List" + } + }, "Resources": { + "AccessPoint": { + "Properties": { + "FileSystemId": { + "Ref": "EfsFileSystem" + } + }, + "Type": "AWS::EFS::AccessPoint" + }, "EfsFileSystem": { "Type": "AWS::EFS::FileSystem" - }, + }, "LambdaFunctionWithEfs": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "ZipFile": "const fs = require('fs')\nconst path = require('path')\nconst efsMountPath = '/mnt/efs'\n\nexports.handler = async (event, context, callback) => {\nconst directory = path.join(efsMountPath, event.body)\nconst files = fs.readdirSync(directory)\nreturn files\n}\n" - }, - "VpcConfig": { - "SubnetIds": { - "Ref": "VpcSubnetIds" - }, - "SecurityGroupIds": { - "Ref": "SecurityGroupIds" - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "LambdaFunctionWithEfsRole", - "Arn" - ] - }, - "Timeout": 3, + }, "FileSystemConfigs": [ { "Arn": { "Fn::GetAtt": [ - "AccessPoint", + "AccessPoint", "Arn" ] - }, + }, "LocalMountPath": "/mnt/EFS" } - ], - "Runtime": "nodejs12.x" - } - }, - "MountTarget": { - "Type": "AWS::EFS::MountTarget", - "Properties": { - "SubnetId": "subnet-abc123", - "FileSystemId": { - "Ref": "EfsFileSystem" - }, - "SecurityGroups": { - "Ref": "SecurityGroupIds" + ], + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionWithEfsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3, + "VpcConfig": { + "SecurityGroupIds": { + "Ref": "SecurityGroupIds" + }, + "SubnetIds": { + "Ref": "VpcSubnetIds" + } } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "LambdaFunctionWithEfsRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "AccessPoint": { - "Type": "AWS::EFS::AccessPoint", + }, + "Type": "AWS::IAM::Role" + }, + "MountTarget": { "Properties": { "FileSystemId": { "Ref": "EfsFileSystem" - } - } - } - }, - "Description": "SAM + Lambda + EFS", - "Parameters": { - "ExistingEfsFileSystem": { - "Type": "String" - }, - "VpcSubnetIds": { - "Type": "List", - "Description": "VPC Subnet IDs that Lambda will use" - }, - "SecurityGroupIds": { - "Type": "List", - "Description": "Security Group IDs that Lambda will use" + }, + "SecurityGroups": { + "Ref": "SecurityGroupIds" + }, + "SubnetId": "subnet-abc123" + }, + "Type": "AWS::EFS::MountTarget" } } } diff --git a/tests/translator/output/function_with_function_url_config.json b/tests/translator/output/function_with_function_url_config.json index 71edd29579..2c8d3be74f 100644 --- a/tests/translator/output/function_with_function_url_config.json +++ b/tests/translator/output/function_with_function_url_config.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,59 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -84,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -95,7 +55,47 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_function_url_config_and_autopublishalias.json b/tests/translator/output/function_with_function_url_config_and_autopublishalias.json index 82d8dd8e16..2686f2da63 100644 --- a/tests/translator/output/function_with_function_url_config_and_autopublishalias.json +++ b/tests/translator/output/function_with_function_url_config_and_autopublishalias.json @@ -1,125 +1,125 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, - "Resources": { - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Handler": "index.handler", - "MemorySize": 1024, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Timeout": 3, - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, + "Resources": { + "MyFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "MyFunctionVersion7eab81fa22": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", - "Properties": { - "FunctionName": { - "Ref": "MyFunction" - } - } + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "MyFunctionRole", + "Arn" + ] }, - "MyFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "Name": "live", - "FunctionName": { - "Ref": "MyFunction" - }, - "FunctionVersion": { - "Fn::GetAtt": [ - "MyFunctionVersion7eab81fa22", - "Version" - ] - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MyFunction" }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunctionAliaslive" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } + "FunctionVersion": { + "Fn::GetAtt": [ + "MyFunctionVersion7eab81fa22", + "Version" + ] }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunctionAliaslive" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MyFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" ] + } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunctionAliaslive" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunctionAliaslive" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" + }, + "MyFunctionVersion7eab81fa22": { + "DeletionPolicy": "Retain", + "Properties": { + "FunctionName": { + "Ref": "MyFunction" } + }, + "Type": "AWS::Lambda::Version" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/function_with_function_url_config_conditions.json b/tests/translator/output/function_with_function_url_config_conditions.json index 9fa4a6b0b8..94cc22817f 100644 --- a/tests/translator/output/function_with_function_url_config_conditions.json +++ b/tests/translator/output/function_with_function_url_config_conditions.json @@ -11,7 +11,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Condition": "MyCondition", "Properties": { "Code": { @@ -28,62 +27,20 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Condition": "MyCondition", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Condition": "MyCondition", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Condition": "MyCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -96,7 +53,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -107,7 +65,49 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Condition": "MyCondition", + "Properties": { + "AuthType": "NONE", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_function_url_config_with_iam_authorization_type.json b/tests/translator/output/function_with_function_url_config_with_iam_authorization_type.json index ae305ca1a5..3e12b5ff9c 100644 --- a/tests/translator/output/function_with_function_url_config_with_iam_authorization_type.json +++ b/tests/translator/output/function_with_function_url_config_with_iam_authorization_type.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,48 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "AWS_IAM", - "Cors": { - "AllowOrigins": [ - "https://example.com", - "example1.com", - "example2.com", - "example2.com" - ], - "AllowMethods": [ - "GET" - ], - "AllowCredentials": true, - "AllowHeaders": [ - "x-Custom-Header" - ], - "ExposeHeaders": [ - "x-amzn-header" - ], - "MaxAge": 10 - } - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -73,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -84,7 +55,36 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "AWS_IAM", + "Cors": { + "AllowCredentials": true, + "AllowHeaders": [ + "x-Custom-Header" + ], + "AllowMethods": [ + "GET" + ], + "AllowOrigins": [ + "https://example.com", + "example1.com", + "example2.com", + "example2.com" + ], + "ExposeHeaders": [ + "x-amzn-header" + ], + "MaxAge": 10 + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_function_url_config_with_intrinsics.json b/tests/translator/output/function_with_function_url_config_with_intrinsics.json index dd9863d3cf..e33107473b 100644 --- a/tests/translator/output/function_with_function_url_config_with_intrinsics.json +++ b/tests/translator/output/function_with_function_url_config_with_intrinsics.json @@ -1,22 +1,21 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { - "AuthorizationTypeRef": { - "Type": "String", - "Default": "NONE" + "AllowMethodsRef": { + "Default": "GET", + "Type": "CommaDelimitedList" }, "AllowOriginsRef": { - "Type": "CommaDelimitedList", - "Default": "https://example.com" + "Default": "https://example.com", + "Type": "CommaDelimitedList" }, - "AllowMethodsRef": { - "Type": "CommaDelimitedList", - "Default": "GET" + "AuthorizationTypeRef": { + "Default": "NONE", + "Type": "String" } }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -32,39 +31,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": { - "Ref": "AuthorizationTypeRef" - }, - "Cors": { - "AllowOrigins": { - "Ref": "AllowOriginsRef" - }, - "AllowMethods": { - "Ref": "AllowMethodsRef" - } - } - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -77,7 +56,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -88,7 +68,27 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": { + "Ref": "AuthorizationTypeRef" + }, + "Cors": { + "AllowMethods": { + "Ref": "AllowMethodsRef" + }, + "AllowOrigins": { + "Ref": "AllowOriginsRef" + } + }, + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_function_url_config_without_cors_config.json b/tests/translator/output/function_with_function_url_config_without_cors_config.json index f0863b3e69..07520fa011 100644 --- a/tests/translator/output/function_with_function_url_config_without_cors_config.json +++ b/tests/translator/output/function_with_function_url_config_without_cors_config.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -19,40 +18,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ] - } - }, - "MyFunctionUrl": { - "Type": "AWS::Lambda::Url", - "Properties": { - "TargetFunctionArn": { - "Ref": "MyFunction" - }, - "AuthType": "NONE" - } - }, - "MyFunctionUrlPublicPermissions": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunctionUrl", - "FunctionName": { - "Ref": "MyFunction" - }, - "Principal": "*", - "FunctionUrlAuthType": "NONE" - } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +43,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,7 +55,28 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MyFunctionUrl": { + "Properties": { + "AuthType": "NONE", + "TargetFunctionArn": { + "Ref": "MyFunction" + } + }, + "Type": "AWS::Lambda::Url" + }, + "MyFunctionUrlPublicPermissions": { + "Properties": { + "Action": "lambda:InvokeFunctionUrl", + "FunctionName": { + "Ref": "MyFunction" + }, + "FunctionUrlAuthType": "NONE", + "Principal": "*" + }, + "Type": "AWS::Lambda::Permission" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_global_layers.json b/tests/translator/output/function_with_global_layers.json index b40dcd644b..f2fbfb21b7 100644 --- a/tests/translator/output/function_with_global_layers.json +++ b/tests/translator/output/function_with_global_layers.json @@ -1,19 +1,38 @@ { "Resources": { - "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "ManyLayersFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:layer1:1", + "arn:aws:lambda:us-east-1:123456789101:layer:layer2:1", + "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" ], + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ManyLayersFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -26,39 +45,20 @@ ] } } - ] - } - } - }, - "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "python3.6", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:layer1:1", - "arn:aws:lambda:us-east-1:123456789101:layer:layer2:1", - "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" ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_intrinsic_architecture.json b/tests/translator/output/function_with_intrinsic_architecture.json index 64c5436828..f8a13a0882 100644 --- a/tests/translator/output/function_with_intrinsic_architecture.json +++ b/tests/translator/output/function_with_intrinsic_architecture.json @@ -1,14 +1,16 @@ { "Parameters": { "ArchitectureRef": { - "Type": "String", - "Default": "arm64" + "Default": "arm64", + "Type": "String" } }, "Resources": { "FunctionWithArchitecturesIntrinsic": { - "Type": "AWS::Lambda::Function", "Properties": { + "Architectures": { + "Ref": "ArchitectureRef" + }, "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" @@ -23,23 +25,19 @@ ] }, "Runtime": "nodejs12.x", - "Timeout": 3, "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } ], - "Architectures": { - "Ref": "ArchitectureRef" - } - } + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithArchitecturesIntrinsicRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -52,7 +50,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -63,7 +62,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_kmskeyarn.json b/tests/translator/output/function_with_kmskeyarn.json index ef7a69f6cc..7daff35285 100644 --- a/tests/translator/output/function_with_kmskeyarn.json +++ b/tests/translator/output/function_with_kmskeyarn.json @@ -1,19 +1,32 @@ { "Resources": { - "FunctionWithKeyArnRole": { - "Type": "AWS::IAM::Role", + "FunctionWithKeyArn": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "KmsKeyArn": "thisIsaKey", + "Role": { + "Fn::GetAtt": [ + "FunctionWithKeyArnRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithKeyArnRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -26,24 +39,50 @@ ] } } - ] - } - } - }, - "FunctionWithReferenceToKeyArnRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithReferenceToKeyArn": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "KmsKeyArn": { + "Ref": "myKey" + }, + "Role": { + "Fn::GetAtt": [ + "FunctionWithReferenceToKeyArnRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithReferenceToKeyArnRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,82 +95,43 @@ ] } } - ] - } - } - }, - "FunctionWithKeyArn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + ], + "Version": "2012-10-17" }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "KmsKeyArn": "thisIsaKey", - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithKeyArnRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ] + }, + "Type": "AWS::IAM::Role" }, "myKey": { - "Type": "AWS::KMS::Key", "Properties": { + "Description": "A sample key", "KeyPolicy": { - "Version": "2012-10-17", "Id": "key-default-1", "Statement": [ { "Action": [ "kms:Create*" ], - "Sid": "Allow administration of the key", - "Resource": "*", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::123456789012:user/Alice" - } + }, + "Resource": "*", + "Sid": "Allow administration of the key" } - ] - }, - "Description": "A sample key" - } - }, - "FunctionWithReferenceToKeyArn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "KmsKeyArn": { - "Ref": "myKey" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionWithReferenceToKeyArnRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ], + "Version": "2012-10-17" + } + }, + "Type": "AWS::KMS::Key" } } } diff --git a/tests/translator/output/function_with_layers.json b/tests/translator/output/function_with_layers.json index 9d660ef494..46089e5673 100644 --- a/tests/translator/output/function_with_layers.json +++ b/tests/translator/output/function_with_layers.json @@ -1,246 +1,246 @@ { "Resources": { - "MinimalLayerFunction": { - "Type": "AWS::Lambda::Function", + "FunctionLayerWithSubIntrinsic": { "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalLayerFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "MyLayera5167acaba": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "MyLayer" - } - }, - "FunctionReferencesLayer": { - "Type": "AWS::Lambda::Function", - "Properties": { + }, + "Handler": "hello.handler", "Layers": [ { - "Ref": "MyLayera5167acaba" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Tags": [ + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpXLayer:1" + }, { - "Value": "SAM", - "Key": "lambda:createdBy" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:CorpYLayer:1" } - ], - "Handler": "hello.handler", + ], "Role": { "Fn::GetAtt": [ - "FunctionReferencesLayerRole", + "FunctionLayerWithSubIntrinsicRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "MinimalLayerFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionLayerWithSubIntrinsicRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionReferencesLayerRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionNoLayerVersion": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" ], + "Role": { + "Fn::GetAtt": [ + "FunctionNoLayerVersionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionNoLayerVersionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionLayerWithSubIntrinsic": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ - { - "Fn::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" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "FunctionLayerWithSubIntrinsicRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "FunctionNoLayerVersion": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionReferencesLayer": { "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" - ], "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ + }, + "Handler": "hello.handler", + "Layers": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "MyLayera5167acaba" } - ], - "Handler": "hello.handler", + ], "Role": { "Fn::GetAtt": [ - "FunctionNoLayerVersionRole", + "FunctionReferencesLayerRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "FunctionNoLayerVersionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionReferencesLayerRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionLayerWithSubIntrinsicRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MinimalLayerFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:CorpXLayer:1" ], + "Role": { + "Fn::GetAtt": [ + "MinimalLayerFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalLayerFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_many_layers.json b/tests/translator/output/function_with_many_layers.json index 96e64d886a..1ebf75dedc 100644 --- a/tests/translator/output/function_with_many_layers.json +++ b/tests/translator/output/function_with_many_layers.json @@ -1,81 +1,81 @@ { "Resources": { - "MyLayera5167acaba": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "layer.zip" - }, - "LayerName": "MyLayer" - } - }, - "ManyLayersFuncRole": { - "Type": "AWS::IAM::Role", + "ManyLayersFunc": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Layers": [ + "arn:aws:lambda:us-east-1:123456789101:layer:z:1", + { + "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" + }, + "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" + }, + { + "Ref": "MyLayera5167acaba" + } ], + "Role": { + "Fn::GetAtt": [ + "ManyLayersFuncRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ManyLayersFuncRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ManyLayersFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ - "arn:aws:lambda:us-east-1:123456789101:layer:z:1", - { - "Fn::Sub": "arn:aws:lambda:${AWS::Region}:123456789101:layer:a:1" - }, - "arn:aws:lambda:us-east-1:123456789101:layer:d12345678:1", - { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:123456789101:layer:c:1" - }, - { - "Ref": "MyLayera5167acaba" - } - ], - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "ManyLayersFuncRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayera5167acaba": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "layer.zip" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_mq_virtual_host.json b/tests/translator/output/function_with_mq_virtual_host.json index 646218535c..98adf98f5c 100644 --- a/tests/translator/output/function_with_mq_virtual_host.json +++ b/tests/translator/output/function_with_mq_virtual_host.json @@ -1,7 +1,6 @@ { "Resources": { "MQFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,34 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MQFunctionMyMQQueue": { + "Properties": { + "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", + "FunctionName": { + "Ref": "MQFunction" + }, + "Queues": [ + "Queue1" + ], + "SourceAccessConfigurations": [ + { + "Type": "BASIC_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Type": "VIRTUAL_HOST", + "URI": "vhost_name" + } + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MQFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,14 +60,14 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "SamAutoGeneratedAMQPolicy", "PolicyDocument": { "Statement": [ { @@ -65,7 +85,8 @@ "Resource": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9" } ] - } + }, + "PolicyName": "SamAutoGeneratedAMQPolicy" } ], "Tags": [ @@ -74,29 +95,8 @@ "Value": "SAM" } ] - } - }, - "MQFunctionMyMQQueue": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": "arn:aws:mq:us-east-2:123456789012:broker:MyBroker:b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9", - "FunctionName": { - "Ref": "MQFunction" - }, - "Queues": [ - "Queue1" - ], - "SourceAccessConfigurations": [ - { - "Type": "BASIC_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Type": "VIRTUAL_HOST", - "URI": "vhost_name" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_msk.json b/tests/translator/output/function_with_msk.json index 85efdd4d94..a2ad0bc689 100644 --- a/tests/translator/output/function_with_msk.json +++ b/tests/translator/output/function_with_msk.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "MyMskStreamProcessor": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,30 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyMskStreamProcessorMyMskEvent": { + "Properties": { + "AmazonManagedKafkaEventSourceConfig": { + "ConsumerGroupId": "consumergroup1" + }, + "EventSourceArn": { + "Fn::Sub": "arn:aws:kafka:${AWS::Region}:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" + }, + "FunctionName": { + "Ref": "MyMskStreamProcessor" + }, + "StartingPosition": "LATEST", + "Topics": [ + "MyDummyTestTopic" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyMskStreamProcessorRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +58,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -54,25 +71,8 @@ "Value": "SAM" } ] - } - }, - "MyMskStreamProcessorMyMskEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Fn::Sub": "arn:aws:kafka:${AWS::Region}:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" - }, - "FunctionName": { - "Ref": "MyMskStreamProcessor" - }, - "StartingPosition": "LATEST", - "Topics": [ - "MyDummyTestTopic" - ], - "AmazonManagedKafkaEventSourceConfig": { - "ConsumerGroupId": "consumergroup1" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_msk_with_intrinsics.json b/tests/translator/output/function_with_msk_with_intrinsics.json index 69eee53378..9415affae9 100644 --- a/tests/translator/output/function_with_msk_with_intrinsics.json +++ b/tests/translator/output/function_with_msk_with_intrinsics.json @@ -1,26 +1,25 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Parameters": { + "ConsumerGroupValue": { + "Default": "consumergroup1", + "Type": "String" + }, "StartingPositionValue": { - "Type": "String", - "Default": "LATEST" + "Default": "LATEST", + "Type": "String" }, "StreamValue": { - "Type": "String", - "Default": "arn:aws:kafka:us-east-1:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2" + "Default": "arn:aws:kafka:us-east-1:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", + "Type": "String" }, "TopicsValue": { - "Type": "CommaDelimitedList", - "Default": "Topic" - }, - "ConsumerGroupValue": { - "Type": "String", - "Default": "consumergroup1" + "Default": "Topic", + "Type": "CommaDelimitedList" } }, "Resources": { "MyMskStreamProcessor": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -40,13 +39,34 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "MyMskStreamProcessorMyMskEvent": { + "Properties": { + "AmazonManagedKafkaEventSourceConfig": { + "ConsumerGroupId": { + "Ref": "ConsumerGroupValue" + } + }, + "EventSourceArn": { + "Ref": "StreamValue" + }, + "FunctionName": { + "Ref": "MyMskStreamProcessor" + }, + "StartingPosition": { + "Ref": "StartingPositionValue" + }, + "Topics": { + "Ref": "TopicsValue" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MyMskStreamProcessorRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -59,7 +79,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -71,29 +92,8 @@ "Value": "SAM" } ] - } - }, - "MyMskStreamProcessorMyMskEvent": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "EventSourceArn": { - "Ref": "StreamValue" - }, - "FunctionName": { - "Ref": "MyMskStreamProcessor" - }, - "StartingPosition": { - "Ref": "StartingPositionValue" - }, - "Topics": { - "Ref": "TopicsValue" - }, - "AmazonManagedKafkaEventSourceConfig": { - "ConsumerGroupId": { - "Ref": "ConsumerGroupValue" - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_null_events.json b/tests/translator/output/function_with_null_events.json index 8623c35a89..7cc118ad21 100644 --- a/tests/translator/output/function_with_null_events.json +++ b/tests/translator/output/function_with_null_events.json @@ -1,7 +1,6 @@ { "Resources": { "FunctionWithNullEvents": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithNullEventsRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,7 +50,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_permissions_boundary.json b/tests/translator/output/function_with_permissions_boundary.json index 9e77b87812..adae71616b 100644 --- a/tests/translator/output/function_with_permissions_boundary.json +++ b/tests/translator/output/function_with_permissions_boundary.json @@ -1,58 +1,58 @@ { "Resources": { - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "MinimalFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "hello.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MinimalFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_policy_templates.json b/tests/translator/output/function_with_policy_templates.json index 05c9057cb3..45b27ad613 100644 --- a/tests/translator/output/function_with_policy_templates.json +++ b/tests/translator/output/function_with_policy_templates.json @@ -5,8 +5,7 @@ } }, "Resources": { - "OnePolicyTemplate": { - "Type": "AWS::Lambda::Function", + "AllCombinations": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -15,91 +14,117 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "OnePolicyTemplateRole", + "AllCombinationsRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MultiplePolicyTemplates": { - "Type": "AWS::Lambda::Function", + "AllCombinationsRole": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MultiplePolicyTemplatesRole", - "Arn" - ] + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "OnePolicyTemplateRole": { - "Type": "AWS::IAM::Role", - "Properties": { "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess", "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "OnePolicyTemplateRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "sqs:ChangeMessageVisibility", - "sqs:ChangeMessageVisibilityBatch", - "sqs:DeleteMessage", - "sqs:DeleteMessageBatch", - "sqs:GetQueueAttributes", - "sqs:ReceiveMessage" + "dynamodb:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ] + }, + "PolicyName": "AllCombinationsRolePolicy0" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { - "queueName": { - "Fn::Sub": [ - "Some${value}", - { - "value": "KeyId" - } - ] + "functionName": { + "Ref": "FunctionNameParam" } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "AllCombinationsRolePolicy2" } ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MultiplePolicyTemplates": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MultiplePolicyTemplatesRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MultiplePolicyTemplatesRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -112,25 +137,14 @@ ] } } - ] - } - } - }, - "MultiplePolicyTemplatesRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "MultiplePolicyTemplatesRolePolicy0", "PolicyDocument": { "Statement": [ { @@ -142,6 +156,7 @@ "sqs:GetQueueAttributes", "sqs:ReceiveMessage" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -149,20 +164,20 @@ "queueName": "Somekey" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MultiplePolicyTemplatesRolePolicy0" }, { - "PolicyName": "MultiplePolicyTemplatesRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -170,33 +185,23 @@ "functionName": "Some function" } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "MultiplePolicyTemplatesRolePolicy1" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "AllCombinations": { - "Type": "AWS::Lambda::Function", + "OnePolicyTemplate": { "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -205,89 +210,84 @@ "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "AllCombinationsRole", + "OnePolicyTemplateRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "AllCombinationsRole": { - "Type": "AWS::IAM::Role", + "OnePolicyTemplateRole": { "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess", "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "Policies": [ { - "PolicyName": "AllCombinationsRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ - "dynamodb:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } - }, - { - "PolicyName": "AllCombinationsRolePolicy2", - "PolicyDocument": { - "Statement": [ - { - "Action": [ - "lambda:InvokeFunction" + "sqs:ChangeMessageVisibility", + "sqs:ChangeMessageVisibilityBatch", + "sqs:DeleteMessage", + "sqs:DeleteMessageBatch", + "sqs:GetQueueAttributes", + "sqs:ReceiveMessage" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", { - "functionName": { - "Ref": "FunctionNameParam" + "queueName": { + "Fn::Sub": [ + "Some${value}", + { + "value": "KeyId" + } + ] } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "OnePolicyTemplateRolePolicy0" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/function_with_request_parameters.json b/tests/translator/output/function_with_request_parameters.json index 940a797106..e75c213f3d 100644 --- a/tests/translator/output/function_with_request_parameters.json +++ b/tests/translator/output/function_with_request_parameters.json @@ -1,13 +1,61 @@ { "Resources": { + "Api": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "parameters": [ + { + "in": "header", + "name": "Authorization", + "required": true, + "type": "string" + } + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "cacheKeyParameters": [ + "method.request.header.Authorization" + ], + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" + } + } + } + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiDeploymentb45131471b": { + "Properties": { + "Description": "RestApi deployment id: b45131471b437edb4cca88487357f3bfbcf59866", + "RestApiId": { + "Ref": "Api" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ApiParameterFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "ApiParameterFunctionRole", @@ -17,66 +65,35 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "NoApiParameterFunctionRole": { - "Type": "AWS::IAM::Role", + "ApiParameterFunctionGetHtmlPermissionProd": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ApiParameterFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": "Api", + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiDeployment104b236830": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 104b236830d26d2515909073d13fa9c58ad6db49", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, "ApiParameterFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,193 +106,176 @@ ] } } - ] - } - } - }, - "NoApiParameterFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "NoApiParameterFunction" + ], + "Version": "2012-10-17" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "ApiProdStage": { "Properties": { "DeploymentId": { - "Ref": "ServerlessRestApiDeployment104b236830" + "Ref": "ApiDeploymentb45131471b" }, "RestApiId": { - "Ref": "ServerlessRestApi" + "Ref": "Api" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage" }, - "Api": { - "Type": "AWS::ApiGateway::RestApi", + "NoApiParameterFunction": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${ApiParameterFunction.Arn}/invocations" - }, - "cacheKeyParameters": [ - "method.request.header.Authorization" - ] - }, - "responses": {}, - "parameters": [ - { - "required": true, - "type": "string", - "name": "Authorization", - "in": "header" - } - ] - } - } - }, - "swagger": "2.0" - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "NoApiParameterFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ApiParameterFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "NoApiParameterFunctionGetHtmlPermissionProd": { "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "ApiParameterFunction" + "Ref": "NoApiParameterFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", - "__ApiId__": "Api" + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } - } - }, - "ApiDeploymentb45131471b": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "Api" - }, - "Description": "RestApi deployment id: b45131471b437edb4cca88487357f3bfbcf59866", - "StageName": "Stage" - } + }, + "Type": "AWS::Lambda::Permission" }, - "ApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + "NoApiParameterFunctionRole": { "Properties": { - "DeploymentId": { - "Ref": "ApiDeploymentb45131471b" - }, - "RestApiId": { - "Ref": "Api" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StageName": "Prod" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" - } - }, - "responses": {}, "parameters": [ { - "required": false, - "type": "string", + "in": "query", "name": "type", - "in": "query" + "required": false, + "type": "string" }, { - "required": false, - "type": "string", + "in": "path", "name": "id", - "in": "path" + "required": false, + "type": "string" }, { - "required": false, - "type": "string", + "in": "query", "name": "full.type", - "in": "query" + "required": false, + "type": "string" } - ] + ], + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${NoApiParameterFunction.Arn}/invocations" + } + } } } }, "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "NoApiParameterFunction": { - "Type": "AWS::Lambda::Function", + "ServerlessRestApiDeployment104b236830": { "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" + "Description": "RestApi deployment id: 104b236830d26d2515909073d13fa9c58ad6db49", + "RestApiId": { + "Ref": "ServerlessRestApi" }, - "Role": { - "Fn::GetAtt": [ - "NoApiParameterFunctionRole", - "Arn" - ] + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment104b236830" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_resource_refs.json b/tests/translator/output/function_with_resource_refs.json index d331af50a4..6aeaee50fe 100644 --- a/tests/translator/output/function_with_resource_refs.json +++ b/tests/translator/output/function_with_resource_refs.json @@ -4,193 +4,193 @@ "Value": { "Ref": "MinimalFunctionAliaslive" } - }, - "VersionArn": { + }, + "AliasInSub": { "Value": { - "Ref": "MinimalFunctionVersion640128d35d" + "Fn::Sub": [ + "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", + { + "SomeValue": "World" + } + ] } - }, - "VersionNumber": { + }, + "AliasName": { "Value": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" + "MinimalFunctionAliaslive", + "Name" ] } - }, - "AliasName": { + }, + "MustNotResolve": { "Value": { "Fn::GetAtt": [ - "MinimalFunctionAliaslive", - "Name" + "FunctionWithoutAlias", + "Alias.Name" ] } - }, + }, "UnResolvedVersion": { "Value": { "Ref": "FunctionWithoutAlias.Version" } - }, - "AliasInSub": { + }, + "VersionArn": { "Value": { - "Fn::Sub": [ - "Hello ${MinimalFunctionAliaslive} ${MinimalFunctionAliaslive.Name} ${SomeValue}", - { - "SomeValue": "World" - } - ] + "Ref": "MinimalFunctionVersion640128d35d" } - }, - "MustNotResolve": { + }, + "VersionNumber": { "Value": { "Fn::GetAtt": [ - "FunctionWithoutAlias", - "Alias.Name" + "MinimalFunctionVersion640128d35d", + "Version" ] } } - }, + }, "Resources": { "FunctionWithoutAlias": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "FunctionWithoutAliasRole", + "FunctionWithoutAliasRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithoutAliasRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionWithoutAliasRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "MinimalFunctionAliaslive": { + "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, + "FunctionVersion": { + "Fn::GetAtt": [ + "MinimalFunctionVersion640128d35d", + "Version" + ] + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion640128d35d": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } - }, + }, + "Type": "AWS::Lambda::Version" + }, "MyBucket": { - "Type": "AWS::S3::Bucket", "Properties": { "Name": { "Fn::GetAtt": [ - "MinimalFunctionAliaslive", + "MinimalFunctionAliaslive", "Name" ] } - } - }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", - "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", - "Version" - ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, - "Name": "live" - } + }, + "Type": "AWS::S3::Bucket" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_self_managed_kafka.json b/tests/translator/output/function_with_self_managed_kafka.json index 1714f44cc8..fe5de62f92 100644 --- a/tests/translator/output/function_with_self_managed_kafka.json +++ b/tests/translator/output/function_with_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,48 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SelfManagedKafkaEventSourceConfig": { + "ConsumerGroupId": "consumergroup1" + }, + "SourceAccessConfigurations": [ + { + "Type": "SASL_SCRAM_512_AUTH", + "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" + }, + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +76,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -82,43 +117,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "SASL_SCRAM_512_AUTH", - "URI": "arn:aws:secretsmanager:us-west-2:123456789012:secret:my-path/my-secret-name-1a2b3c" - }, - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - }, - "SelfManagedKafkaEventSourceConfig": { - "ConsumerGroupId": "consumergroup1" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_signing_profile.json b/tests/translator/output/function_with_signing_profile.json index 1b878970d3..ee545e51eb 100644 --- a/tests/translator/output/function_with_signing_profile.json +++ b/tests/translator/output/function_with_signing_profile.json @@ -1,36 +1,34 @@ { "Resources": { "FunctionWithSigningProfile": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.gethtml", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "member_portal.zip" }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], + "CodeSigningConfigArn": { + "Ref": "MySignedFunctionCodeSigningConfig" + }, + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ "FunctionWithSigningProfileRole", "Arn" ] }, - "CodeSigningConfigArn": { - "Ref": "MySignedFunctionCodeSigningConfig" - } - } + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "FunctionWithSigningProfileRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -43,25 +41,23 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySignedFunctionCodeSigningConfig": { - "Type": "AWS::Lambda::CodeSigningConfig", "Properties": { - "CodeSigningPolicies": { - "UntrustedArtifactOnDeployment": "Enforce" - }, "AllowedPublishers": { "SigningProfileVersionArns": [ { @@ -72,14 +68,18 @@ } ] }, + "CodeSigningPolicies": { + "UntrustedArtifactOnDeployment": "Enforce" + }, "Description": "Code Signing for MySignedLambdaFunction" - } + }, + "Type": "AWS::Lambda::CodeSigningConfig" }, "SigningProfile": { - "Type": "AWS::Signer::SigningProfile", "Properties": { "PlatformId": "AWSLambda-SHA384-ECDSA" - } + }, + "Type": "AWS::Signer::SigningProfile" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/function_with_sns_event_source_all_parameters.json b/tests/translator/output/function_with_sns_event_source_all_parameters.json index e999e3eb8e..937c464624 100644 --- a/tests/translator/output/function_with_sns_event_source_all_parameters.json +++ b/tests/translator/output/function_with_sns_event_source_all_parameters.json @@ -1,22 +1,47 @@ { "Resources": { + "MyAwesomeFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyAwesomeFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "MyAwesomeFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "MyAwesomeFunction", + "Arn" + ] + }, "FilterPolicy": { - "store": [ - "example_corp" + "customer_interests": [ + "rugby", + "football", + "baseball" ], "event": [ { "anything-but": "order_cancelled" } ], - "customer_interests": [ - "rugby", - "football", - "baseball" - ], "price_usd": [ { "numeric": [ @@ -24,44 +49,31 @@ 100 ] } - ] - }, - "Endpoint": { - "Fn::GetAtt": [ - "MyAwesomeFunction", - "Arn" + ], + "store": [ + "example_corp" ] }, "Protocol": "lambda", - "TopicArn": "topicArn", - "Region": "region" - } + "Region": "region", + "TopicArn": "topicArn" + }, + "Type": "AWS::SNS::Subscription" }, "MyAwesomeFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", "FunctionName": { "Ref": "MyAwesomeFunction" }, + "Principal": "sns.amazonaws.com", "SourceArn": "topicArn" - } + }, + "Type": "AWS::Lambda::Permission" }, "MyAwesomeFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -74,32 +86,20 @@ ] } } - ] - } - } - }, - "MyAwesomeFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MyAwesomeFunctionRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "python2.7", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/function_with_vpc_permission_for_self_managed_kafka.json b/tests/translator/output/function_with_vpc_permission_for_self_managed_kafka.json index 3ecb677fd2..87b48fac14 100644 --- a/tests/translator/output/function_with_vpc_permission_for_self_managed_kafka.json +++ b/tests/translator/output/function_with_vpc_permission_for_self_managed_kafka.json @@ -3,7 +3,6 @@ "Parameters": {}, "Resources": { "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -23,13 +22,41 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": [ + "abc.xyz.com:9092", + "123.45.67.89:9096" + ] + } + }, + "SourceAccessConfigurations": [ + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + } + ], + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -42,7 +69,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -75,36 +103,8 @@ "Value": "SAM" } ] - } - }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": [ - "Topic1" - ], - "SourceAccessConfigurations": [ - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": [ - "abc.xyz.com:9092", - "123.45.67.89:9096" - ] - } - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/global_handle_path_level_parameter.json b/tests/translator/output/global_handle_path_level_parameter.json index 64abf7bd29..1eed923460 100644 --- a/tests/translator/output/global_handle_path_level_parameter.json +++ b/tests/translator/output/global_handle_path_level_parameter.json @@ -1,102 +1,47 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { - "parameters": [ - { - "required": true, - "type": "string", - "description": "Application domain", - "name": "domain", - "in": "path" - } - ], "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "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" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} - } + } + }, + "parameters": [ + { + "description": "Application domain", + "in": "path", + "name": "domain", + "required": true, + "type": "string" + } + ] } }, - "swagger": 2.0, "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -110,83 +55,116 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": 2.0 }, "Name": "some api" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentdb4b9da82a" - } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "ServerlessRestApiDeploymentdb4b9da82a": { - "Type": "AWS::ApiGateway::Deployment", + "ExplicitApiDeployment9a254aa466": { "Properties": { + "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", "RestApiId": { - "Ref": "ServerlessRestApi" + "Ref": "ExplicitApi" }, - "Description": "RestApi deployment id: db4b9da82adc6031fcd32bf3a4954485464fc009", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment9a254aa466" + }, "RestApiId": { "Ref": "ExplicitApi" }, "StageName": "SomeStage", - "CacheClusterSize": "1.6", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment9a254aa466" } - } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "ImplicitApiFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "MyUserPool": { - "Type": "AWS::Cognito::UserPool", + "ImplicitApiFunctionRole": { "Properties": { - "UsernameAttributes": [ - "email" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "UserPoolName": "UserPoolName", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyUserPool": { + "Properties": { "Policies": { "PasswordPolicy": { "MinimumLength": 8 @@ -195,57 +173,50 @@ "Schema": [ { "AttributeDataType": "String", - "Required": false, - "Name": "email" + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, - "ExplicitApiDeployment9a254aa466": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 9a254aa466c6f818951dfb6e45fde65489beb153", - "StageName": "Stage" - } + }, + "Type": "AWS::Cognito::UserPool" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { "get": { + "responses": {}, + "security": [ + { + "MyCognitoAuth": [] + } + ], "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" } - }, - "security": [ - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } } } }, - "swagger": "2.0", "securityDefinitions": { "MyCognitoAuth": { "in": "header", - "type": "apiKey", "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { @@ -259,10 +230,39 @@ }, "x-amazon-apigateway-authtype": "cognito_user_pools" } - } + }, + "swagger": "2.0" }, "Name": "some api" - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentdb4b9da82a": { + "Properties": { + "Description": "RestApi deployment id: db4b9da82adc6031fcd32bf3a4954485464fc009", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentdb4b9da82a" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/globals_for_api.json b/tests/translator/output/globals_for_api.json index 6cb00f73fd..6c624d7f4e 100644 --- a/tests/translator/output/globals_for_api.json +++ b/tests/translator/output/globals_for_api.json @@ -1,275 +1,275 @@ { "Resources": { - "ImplicitApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.gethtml", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "member_portal.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ImplicitApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "ImplicitApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ServerlessRestApiDeploymentaa32438b68": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aa32438b68e05d3771a975585dfbc7b012672b55", - "StageName": "Stage" - } - }, "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "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": {}, "security": [ { "MyCognitoAuth": [] - }, + }, { "api_key": [] } - ], - "responses": {} + ], + "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" + } + } } } - }, - "swagger": 2.0, + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": 2.0 + }, "Name": "some api" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment43e01e673d": { "Properties": { + "Description": "RestApi deployment id: 43e01e673d7acbd09e4c38ff78dd6ddaf2ed1d55", "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod", - "CacheClusterSize": "1.6", - "Variables": { - "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaa32438b68" - } - } - }, + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ExplicitApiSomeStageStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ExplicitApiDeployment43e01e673d" + }, "RestApiId": { "Ref": "ExplicitApi" - }, - "StageName": "SomeStage", - "CacheClusterSize": "1.6", + }, + "StageName": "SomeStage", "Variables": { "SomeVar": "Value" - }, - "CacheClusterEnabled": true, - "DeploymentId": { - "Ref": "ExplicitApiDeployment43e01e673d" } - } - }, - "ExplicitApiDeployment43e01e673d": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ImplicitApiFunction": { "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 43e01e673d7acbd09e4c38ff78dd6ddaf2ed1d55", - "StageName": "Stage" - } - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "ImplicitApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "ImplicitApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "ImplicitApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, + "ImplicitApiFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MyUserPool": { - "Type": "AWS::Cognito::UserPool", "Properties": { - "UsernameAttributes": [ - "email" - ], - "UserPoolName": "UserPoolName", "Policies": { "PasswordPolicy": { "MinimumLength": 8 } - }, + }, "Schema": [ { - "AttributeDataType": "String", - "Required": false, - "Name": "email" + "AttributeDataType": "String", + "Name": "email", + "Required": false } + ], + "UserPoolName": "UserPoolName", + "UsernameAttributes": [ + "email" ] - } - }, + }, + "Type": "AWS::Cognito::UserPool" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/": { "get": { - "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": {}, "security": [ { "MyCognitoAuth": [] - }, + }, { "api_key": [] } - ], - "responses": {} + ], + "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" + } + } } } - }, - "swagger": "2.0", + }, "securityDefinitions": { "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", + "in": "header", + "name": "Authorization", + "type": "apiKey", "x-amazon-apigateway-authorizer": { "providerARNs": [ { "Fn::GetAtt": [ - "MyUserPool", + "MyUserPool", "Arn" ] } - ], + ], "type": "cognito_user_pools" - }, + }, "x-amazon-apigateway-authtype": "cognito_user_pools" - }, + }, "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } - }, + }, + "swagger": "2.0" + }, "Name": "some api" - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaa32438b68": { + "Properties": { + "Description": "RestApi deployment id: aa32438b68e05d3771a975585dfbc7b012672b55", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "CacheClusterEnabled": true, + "CacheClusterSize": "1.6", + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaa32438b68" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod", + "Variables": { + "SomeVar": "Value" + } + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/globals_for_function.json b/tests/translator/output/globals_for_function.json index 65afb46771..6668b0fb42 100644 --- a/tests/translator/output/globals_for_function.json +++ b/tests/translator/output/globals_for_function.json @@ -1,251 +1,255 @@ { "Resources": { - "FunctionWithOverridesRole": { - "Type": "AWS::IAM::Role", + "FunctionWithOverrides": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess", - "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, + "Architectures": [ + "x86_64" + ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Environment": { + "Variables": { + "Var1": "value1", + "Var2": "value2", + "Var3": "value3" + } + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "index.handler", + "Layers": [ { - "Value": "newvalue1", - "Key": "newtag1" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" }, { - "Value": "value1", - "Key": "tag1" + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + "MemorySize": 512, + "ReservedConcurrentExecutions": 100, + "Role": { + "Fn::GetAtt": [ + "FunctionWithOverridesRole", + "Arn" ] - } - } - }, - "FunctionWithOverrides": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Layers": [ + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" - }, + "Key": "lambda:createdBy", + "Value": "SAM" + }, { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer2:2" + "Key": "newtag1", + "Value": "newvalue1" + }, + { + "Key": "tag1", + "Value": "value1" } - ], + ], + "Timeout": 100, "TracingConfig": { "Mode": "PassThrough" - }, - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, + }, "VpcConfig": { - "SubnetIds": [ - "sub-id-2" - ], "SecurityGroupIds": [ - "sg-edcd9784", + "sg-edcd9784", "sg-123" + ], + "SubnetIds": [ + "sub-id-2" ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "newvalue1", - "Key": "newtag1" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "ReservedConcurrentExecutions": 100, - "Architectures": ["x86_64"], - "EphemeralStorage": { - "Size": 1024 + } + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionWithOverridesAliasprod": { + "Properties": { + "FunctionName": { + "Ref": "FunctionWithOverrides" }, - "MemorySize": 512, - "Environment": { - "Variables": { - "Var1": "value1", - "Var3": "value3", - "Var2": "value2" - } - }, - "Handler": "index.handler", - "Role": { + "FunctionVersion": { "Fn::GetAtt": [ - "FunctionWithOverridesRole", - "Arn" + "FunctionWithOverridesVersion096ed3b52b", + "Version" ] - }, - "Timeout": 100, - "Runtime": "nodejs12.x" - } - }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Name": "prod" + }, + "Type": "AWS::Lambda::Alias" + }, + "FunctionWithOverridesRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess", - "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" - ], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "FunctionWithOverridesAliasprod": { - "Type": "AWS::Lambda::Alias", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/OverridePermissionsBoundary", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "newtag1", + "Value": "newvalue1" + }, + { + "Key": "tag1", + "Value": "value1" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "FunctionWithOverridesVersion096ed3b52b": { + "DeletionPolicy": "Retain", "Properties": { - "FunctionVersion": { - "Fn::GetAtt": [ - "FunctionWithOverridesVersion096ed3b52b", - "Version" - ] - }, "FunctionName": { "Ref": "FunctionWithOverrides" - }, - "Name": "prod" - } - }, + } + }, + "Type": "AWS::Lambda::Version" + }, "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Layers": [ - { - "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" - } - ], - "TracingConfig": { - "Mode": "Active" - }, + "Architectures": [ + "x86_64" + ], "Code": { - "S3Bucket": "global-bucket", + "S3Bucket": "global-bucket", "S3Key": "global.zip" - }, - "VpcConfig": { - "SubnetIds": [ - "sub-id-2" - ], - "SecurityGroupIds": [ - "sg-edcd9784" - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - }, - { - "Value": "value1", - "Key": "tag1" - } - ], - "ReservedConcurrentExecutions": 50, - "Architectures": ["x86_64"], - "EphemeralStorage": { - "Size": 1024 }, - "MemorySize": 1024, "Environment": { "Variables": { - "Var1": "value1", + "Var1": "value1", "Var2": "value2" } - }, - "Handler": "hello.handler", + }, + "EphemeralStorage": { + "Size": 1024 + }, + "Handler": "hello.handler", + "Layers": [ + { + "Fn::Sub": "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:layer:MyLayer:1" + } + ], + "MemorySize": 1024, + "ReservedConcurrentExecutions": 50, "Role": { "Fn::GetAtt": [ - "MinimalFunctionRole", + "MinimalFunctionRole", "Arn" ] - }, - "Timeout": 30, - "Runtime": "python2.7" - } - }, + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "tag1", + "Value": "value1" + } + ], + "Timeout": 30, + "TracingConfig": { + "Mode": "Active" + }, + "VpcConfig": { + "SecurityGroupIds": [ + "sg-edcd9784" + ], + "SubnetIds": [ + "sub-id-2" + ] + } + }, + "Type": "AWS::Lambda::Function" + }, "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", "Properties": { + "FunctionName": { + "Ref": "MinimalFunction" + }, "FunctionVersion": { "Fn::GetAtt": [ "MinimalFunctionVersion0a06fc8fb1", "Version" ] - }, - "FunctionName": { - "Ref": "MinimalFunction" - }, + }, "Name": "live" - } - }, - "FunctionWithOverridesVersion096ed3b52b": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + }, + "Type": "AWS::Lambda::Alias" + }, + "MinimalFunctionRole": { "Properties": { - "FunctionName": { - "Ref": "FunctionWithOverrides" - } - } - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess", + "arn:aws:iam::aws:policy/service-role/AWSLambdaVPCAccessExecutionRole" + ], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + }, + { + "Key": "tag1", + "Value": "value1" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "MinimalFunctionVersion0a06fc8fb1": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::Version", + "DeletionPolicy": "Retain", "Properties": { "FunctionName": { "Ref": "MinimalFunction" } - } + }, + "Type": "AWS::Lambda::Version" } } } diff --git a/tests/translator/output/globals_for_simpletable.json b/tests/translator/output/globals_for_simpletable.json index 313fd286c3..d937d9ef86 100644 --- a/tests/translator/output/globals_for_simpletable.json +++ b/tests/translator/output/globals_for_simpletable.json @@ -1,25 +1,25 @@ { - "Resources": { - "MinimalTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "SSESpecification": { - "SSEEnabled": true - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] + "Resources": { + "MinimalTable": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "SSESpecification": { + "SSEEnabled": true } - } + }, + "Type": "AWS::DynamoDB::Table" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/http_api_custom_iam_auth.json b/tests/translator/output/http_api_custom_iam_auth.json index d4fb4acef7..d502c8ca7e 100644 --- a/tests/translator/output/http_api_custom_iam_auth.json +++ b/tests/translator/output/http_api_custom_iam_auth.json @@ -2,22 +2,42 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionHelloAWSIAMAuthPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "MyApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/hello-aws-iam-auth" ] } @@ -29,9 +49,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -39,7 +65,12 @@ "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -53,7 +84,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -61,13 +95,22 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/hello-aws-iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -80,8 +123,14 @@ } }, "tags": [ - { "name": "Tag1", "x-amazon-apigateway-tag-value": "value1" }, - { "name": "Tag2", "x-amazon-apigateway-tag-value": "value2" }, + { + "name": "Tag1", + "x-amazon-apigateway-tag-value": "value1" + }, + { + "name": "Tag2", + "x-amazon-apigateway-tag-value": "value2" + }, { "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" @@ -93,7 +142,9 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", "Tags": { @@ -106,11 +157,24 @@ }, "MyAuthFn": { "Properties": { - "Code": { "S3Bucket": "bucket", "S3Key": "key" }, + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, "Handler": "index.handler", - "Role": { "Fn::GetAtt": ["Arn", "MyAuthFnRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "MyAuthFnRole" + ] + }, "Runtime": "nodejs12.x", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, @@ -119,9 +183,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -129,7 +199,12 @@ "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" } diff --git a/tests/translator/output/http_api_def_uri.json b/tests/translator/output/http_api_def_uri.json index fd5dedd146..516df22733 100644 --- a/tests/translator/output/http_api_def_uri.json +++ b/tests/translator/output/http_api_def_uri.json @@ -1,151 +1,151 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::Lambda::Function" + }, + "FunctionApi2Permission": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", - "__ApiId__": "MyApi" + "__ApiId__": { + "Ref": "MyApi2" + }, + "__Stage__": "*" } ] } - } - }, - "MyApiStage": { - "Type": "AWS::ApiGatewayV2::Stage", + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionApiPermission": { "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "MyApi" - }, - "DefaultRouteSettings": { - "ThrottlingBurstLimit": 50, - "ThrottlingRateLimit": 100.0 - }, - "StageName": { - "Fn::Join": [ - "", - [ - "Stage", - "Name" - ] + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "Function" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": "MyApi", + "__Stage__": "*" + } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "MyApi": { + "Properties": { + "BodyS3Location": { + "Bucket": "bucket", + "Key": "key" + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2": { + "Properties": { + "BodyS3Location": { + "Bucket": "bucket", + "Key": "key", + "Version": "version" + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { - "AutoDeploy": true, "ApiId": { "Ref": "MyApi2" - }, + }, + "AutoDeploy": true, "DefaultRouteSettings": { "ThrottlingRateLimit": 100.0 - }, + }, "StageName": "$default" - } - }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "BodyS3Location": { - "Version": "version", - "Bucket": "bucket", - "Key": "key" - } - } - }, - "FunctionApi2Permission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApiStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "Function" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi2" - } - } + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "DefaultRouteSettings": { + "ThrottlingBurstLimit": 50, + "ThrottlingRateLimit": 100.0 + }, + "StageName": { + "Fn::Join": [ + "", + [ + "Stage", + "Name" + ] ] } - } - }, - "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "BodyS3Location": { - "Bucket": "bucket", - "Key": "key" - } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/http_api_description.json b/tests/translator/output/http_api_description.json index fed22b6856..e7e4ed5ef8 100644 --- a/tests/translator/output/http_api_description.json +++ b/tests/translator/output/http_api_description.json @@ -1,123 +1,123 @@ { "Resources": { "Function": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "FunctionRole", + "FunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "FunctionApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "Function" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", - "__ApiId__": "HttpApi" + "__ApiId__": "HttpApi", + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, "FunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "HttpApi" - }, - "Tags": { - "httpapi:createdBy": "SAM" - }, - "StageName": "$default" - } - }, + }, + "Type": "AWS::IAM::Role" + }, "HttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "info": { + "description": "my description" + }, "openapi": "3.0.1", "paths": { - "/foo": {}, "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${Function.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {} + } } - } + }, + "/foo": {} }, "tags": [ { "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ], - "info": { - "description": "my description" - } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "HttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "HttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/http_api_existing_openapi.json b/tests/translator/output/http_api_existing_openapi.json index ea696cf89f..2248473aff 100644 --- a/tests/translator/output/http_api_existing_openapi.json +++ b/tests/translator/output/http_api_existing_openapi.json @@ -1,276 +1,276 @@ { "Parameters": { "Timeout": { - "Default": 15000, + "Default": 15000, "Type": "Number" } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "OpenIdAuth": { + "type": "openIdConnect", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "openIdConnectUrl": "https://www.example.com/v1/connect", + "type": "jwt" + } + }, + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/get/{something}/with/{params}": { - "get": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope1", + "scope2" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "timeoutInMillis": { + "Ref": "Timeout" + }, + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {}, - "parameters": [ - { - "required": true, - "name": "something", - "in": "path" - }, - { - "required": true, - "name": "params", - "in": "path" } - ] + } } - }, + }, "/basic": { "post": { - "x-amazon-apigateway-integration": { - "payloadFormatVersion": "1.0", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "httpMethod": "POST", - "timeoutInMillis": 10000 - }, + "responses": {}, "security": [ { "OpenIdAuth": [ "scope3" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "timeoutInMillis": 10000, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } } - }, - "/integration": { - "post": { + }, + "/get/{something}/with/{params}": { + "get": { + "parameters": [ + { + "in": "path", + "name": "something", + "required": true + }, + { + "in": "path", + "name": "params", + "required": true + } + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope1", - "scope2" - ] } - ], - "responses": {} + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/integration": { + "post": { + "responses": {}, "security": [ { "OpenIdAuth": [ - "scope1", + "scope1", "scope2" ] } - ], - "isDefaultRoute": true, + ], "x-amazon-apigateway-integration": { - "payloadFormatVersion": "1.0", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "httpMethod": "POST", - "timeoutInMillis": { - "Ref": "Timeout" } - }, - "responses": {} + } } - }, + }, "/oauth2": { "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } } - }, + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ], "x-amazon-apigateway-cors": { - "allowMethods": [ - "GET" - ], "allowHeaders": [ "x-apigateway-header" - ], + ], + "allowMethods": [ + "GET" + ], "allowOrigins": [ - "https://global.com", + "https://global.com", "https://local.com" - ], + ], "maxAge": 6000 - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ], - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - }, - "OpenIdAuth": { - "type": "openIdConnect", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "openIdConnectUrl": "https://www.example.com/v1/connect" - } - } - } } } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/http_api_existing_openapi_conditions.json b/tests/translator/output/http_api_existing_openapi_conditions.json index f1a6d177d5..43f18732d3 100644 --- a/tests/translator/output/http_api_existing_openapi_conditions.json +++ b/tests/translator/output/http_api_existing_openapi_conditions.json @@ -2,295 +2,295 @@ "Conditions": { "condition": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - }, - "Condition": "condition" - }, - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM", - "Tag1": "value1", - "Tag2": "value2" - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", + "Condition": "condition", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.7", + }, + "Runtime": "python3.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "condition" - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "condition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "condition" - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Condition": "condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "OAuth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + }, + "OpenIdAuth": { + "type": "openIdConnect", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "openIdConnectUrl": "https://www.example.com/v1/connect", + "type": "jwt" + } + }, + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope3" - ] - } - ], - "responses": {} - }, - "get": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OAuth2": [ - "basic" - ] - } - ], - "responses": {} - } - }, - "/integration": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, - "security": [ - { - "OpenIdAuth": [ - "scope1", - "scope2" - ] - } - ], - "responses": {} - } - }, "$default": { "x-amazon-apigateway-any-method": { "Fn::If": [ - "condition", + "condition", { + "isDefaultRoute": true, + "responses": {}, "security": [ { "OpenIdAuth": [ - "scope1", + "scope1", "scope2" ] } - ], - "isDefaultRoute": true, + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "condition", + "condition", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, - "/oauth2": { + }, + "/basic": { + "get": { + "responses": {}, + "security": [ + { + "OAuth2": [ + "basic" + ] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } + }, "post": { + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope3" + ] + } + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations" + } + } + } + }, + "/integration": { + "post": { + "responses": {}, + "security": [ + { + "OpenIdAuth": [ + "scope1", + "scope2" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "1.0" - }, + } + } + } + }, + "/oauth2": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - } - }, - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - }, - "OAuth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "1.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } } - }, - "OpenIdAuth": { - "type": "openIdConnect", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "openIdConnectUrl": "https://www.example.com/v1/connect" - } } } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" }, { - "name": "Tag1", - "x-amazon-apigateway-tag-value": "value1", - "description": "this tag exists, but doesn't have an amazon extension value" - }, + "description": "this tag exists, but doesn't have an amazon extension value", + "name": "Tag1", + "x-amazon-apigateway-tag-value": "value1" + }, { - "name": "Tag2", + "name": "Tag2", "x-amazon-apigateway-tag-value": "value2" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "Tag1": "value1", + "Tag2": "value2", + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } } diff --git a/tests/translator/output/http_api_explicit_stage.json b/tests/translator/output/http_api_explicit_stage.json index 6f827ff3a3..ee59ef6ea1 100644 --- a/tests/translator/output/http_api_explicit_stage.json +++ b/tests/translator/output/http_api_explicit_stage.json @@ -1,160 +1,160 @@ { "Parameters": { "CorsParam": { - "Default": true, + "Default": true, "Type": "String" }, "PayloadFormatVersion": { - "Default": "1.0", - "Type": "String" + "Default": "1.0", + "Type": "String" } }, "Resources": { - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.restapi", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" - }, + }, + "Handler": "index.restapi", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "StageVariables": { - "VarName": "VarValue" - }, - "ApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod", - "AccessLogSettings": { - "DestinationArn": "arn:aws:logs:us-east-1:123456789012:log-group:LogGroupName", - "Format": "$context.requestId" - }, - "RouteSettings": { - "$default": { - "ThrottlingRateLimit": 0.7, - "DataTraceEnabled": true, - "ThrottlingBurstLimit": 300, - "LoggingLevel": "INFO" - } - }, - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { - "FailOnWarnings": true, "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, + "httpMethod": "POST", "payloadFormatVersion": { "Ref": "PayloadFormatVersion" + }, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {} + } } } - }, - "x-amazon-apigateway-cors": { - "allowOrigins": [ - "*" - ] - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ] + ], + "x-amazon-apigateway-cors": { + "allowOrigins": [ + "*" + ] + } + }, + "FailOnWarnings": true + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiProdStage": { + "Properties": { + "AccessLogSettings": { + "DestinationArn": "arn:aws:logs:us-east-1:123456789012:log-group:LogGroupName", + "Format": "$context.requestId" + }, + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "RouteSettings": { + "$default": { + "DataTraceEnabled": true, + "LoggingLevel": "INFO", + "ThrottlingBurstLimit": 300, + "ThrottlingRateLimit": 0.7 + } + }, + "StageName": "Prod", + "StageVariables": { + "VarName": "VarValue" + }, + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/http_api_global_iam_auth_enabled.json b/tests/translator/output/http_api_global_iam_auth_enabled.json index 76c2cbe950..683f386901 100644 --- a/tests/translator/output/http_api_global_iam_auth_enabled.json +++ b/tests/translator/output/http_api_global_iam_auth_enabled.json @@ -2,22 +2,42 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionImplicitApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "ServerlessHttpApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" ] } @@ -27,11 +47,18 @@ "HttpApiFunctionImplicitApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - { "__ApiId__": { "Ref": "ServerlessHttpApi" }, "__Stage__": "*" }, + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" ] } @@ -43,9 +70,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -53,7 +86,12 @@ "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -70,7 +108,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { @@ -89,7 +132,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -113,10 +160,14 @@ }, "ServerlessHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "ServerlessHttpApi" }, + "ApiId": { + "Ref": "ServerlessHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json b/tests/translator/output/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json index ceea480e89..e9e8279554 100644 --- a/tests/translator/output/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json +++ b/tests/translator/output/http_api_global_iam_auth_enabled_with_existing_conflicting_authorizer.json @@ -10,7 +10,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -18,7 +21,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": {}, "tags": [ @@ -33,10 +41,14 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/http_api_lambda_auth.json b/tests/translator/output/http_api_lambda_auth.json index ac6d3b4fbb..8236a5df32 100644 --- a/tests/translator/output/http_api_lambda_auth.json +++ b/tests/translator/output/http_api_lambda_auth.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,149 +71,96 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerPayloadFormatVersion": 1.0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "request" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/basic": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerPayloadFormatVersion": 1.0 } } } @@ -234,22 +180,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "AutoDeploy": true - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/http_api_lambda_auth_full.json b/tests/translator/output/http_api_lambda_auth_full.json index 20b14e6364..37f79be9c1 100644 --- a/tests/translator/output/http_api_lambda_auth_full.json +++ b/tests/translator/output/http_api_lambda_auth_full.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -72,163 +71,110 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "authorizerPayloadFormatVersion": 2.0, + "authorizerResultTtlInSeconds": 60, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "enableSimpleResponses": true, + "identitySource": [ + "$context.contextVar", + "$request.header.Authorization", + "$request.querystring.petId", + "$stageVariables.stageVar" + ], + "type": "request" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/basic": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/basic": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": [ - "MyAuthFn", - "Arn" - ] - } - } - ] - }, - "authorizerCredentials": { - "Fn::GetAtt": [ - "MyAuthFnRole", - "Arn" - ] - }, - "identitySource": [ - "$context.contextVar", - "$request.header.Authorization", - "$request.querystring.petId", - "$stageVariables.stageVar" - ], - "authorizerResultTtlInSeconds": 60, - "authorizerPayloadFormatVersion": 2.0, - "enableSimpleResponses": true } } } @@ -248,22 +194,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" }, - "AutoDeploy": true - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/http_api_local_iam_auth_enabled.json b/tests/translator/output/http_api_local_iam_auth_enabled.json index e79a9585ee..cbd931dd79 100644 --- a/tests/translator/output/http_api_local_iam_auth_enabled.json +++ b/tests/translator/output/http_api_local_iam_auth_enabled.json @@ -2,23 +2,40 @@ "Resources": { "HttpApiFunction": { "Properties": { - "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, "Handler": "index.restapi", - "Role": { "Fn::GetAtt": ["Arn", "HttpApiFunctionRole"] }, + "Role": { + "Fn::GetAtt": [ + "Arn", + "HttpApiFunctionRole" + ] + }, "Runtime": "python3.7", - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::Lambda::Function" }, "HttpApiFunctionMyDefaultIamAuthHttpApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" @@ -30,12 +47,16 @@ "HttpApiFunctionMyDefaultIamAuthHttpApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" @@ -47,12 +68,16 @@ "HttpApiFunctionMyDefaultIamAuthHttpApiNoAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyDefaultIamAuthHttpApi" }, + "__ApiId__": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-auth" @@ -64,12 +89,16 @@ "HttpApiFunctionMyIamAuthEnabledHttpApiDefaultAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyIamAuthEnabledHttpApi" }, + "__ApiId__": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/default-auth" @@ -81,12 +110,16 @@ "HttpApiFunctionMyIamAuthEnabledHttpApiIamAuthEventPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "FunctionName": { "Ref": "HttpApiFunction" }, + "FunctionName": { + "Ref": "HttpApiFunction" + }, "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ { - "__ApiId__": { "Ref": "MyIamAuthEnabledHttpApi" }, + "__ApiId__": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "__Stage__": "*" }, "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/iam-auth" @@ -100,9 +133,15 @@ "AssumeRolePolicyDocument": { "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", - "Principal": { "Service": ["lambda.amazonaws.com"] } + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } ], "Version": "2012-10-17" @@ -110,7 +149,12 @@ "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "Tags": [{ "Key": "lambda:createdBy", "Value": "SAM" }] + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, "Type": "AWS::IAM::Role" }, @@ -127,13 +171,22 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -147,7 +200,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -161,7 +218,11 @@ "/no-auth": { "get": { "responses": {}, - "security": [{ "NONE": [] }], + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -185,10 +246,14 @@ }, "MyDefaultIamAuthHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyDefaultIamAuthHttpApi" }, + "ApiId": { + "Ref": "MyDefaultIamAuthHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" }, @@ -205,7 +270,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": { "/default-auth": { @@ -224,7 +294,11 @@ "/iam-auth": { "get": { "responses": {}, - "security": [{ "AWS_IAM": [] }], + "security": [ + { + "AWS_IAM": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "payloadFormatVersion": "2.0", @@ -248,10 +322,14 @@ }, "MyIamAuthEnabledHttpApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyIamAuthEnabledHttpApi" }, + "ApiId": { + "Ref": "MyIamAuthEnabledHttpApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json b/tests/translator/output/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json index ceea480e89..e9e8279554 100644 --- a/tests/translator/output/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json +++ b/tests/translator/output/http_api_local_iam_auth_enabled_with_existing_conflicting_authorizer.json @@ -10,7 +10,10 @@ "x-amazon-apigateway-authorizer": { "identitySource": "$request.header.Authorization", "jwtConfiguration": { - "audience": ["audience1", "audience2"], + "audience": [ + "audience1", + "audience2" + ], "issuer": "https://www.example.com/v1/connect/oidc" }, "type": "jwt" @@ -18,7 +21,12 @@ } } }, - "info": { "title": { "Ref": "AWS::StackName" }, "version": "1.0" }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, "openapi": "3.0.1", "paths": {}, "tags": [ @@ -33,10 +41,14 @@ }, "MyApiApiGatewayDefaultStage": { "Properties": { - "ApiId": { "Ref": "MyApi" }, + "ApiId": { + "Ref": "MyApi" + }, "AutoDeploy": true, "StageName": "$default", - "Tags": { "httpapi:createdBy": "SAM" } + "Tags": { + "httpapi:createdBy": "SAM" + } }, "Type": "AWS::ApiGatewayV2::Stage" } diff --git a/tests/translator/output/http_api_multiple_authorizers.json b/tests/translator/output/http_api_multiple_authorizers.json index a18e784e79..33da72f8b0 100644 --- a/tests/translator/output/http_api_multiple_authorizers.json +++ b/tests/translator/output/http_api_multiple_authorizers.json @@ -1,7 +1,6 @@ { "Resources": { "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -9,7 +8,10 @@ }, "Handler": "index.restapi", "Role": { - "Fn::GetAtt": ["HttpApiFunctionRole", "Arn"] + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] }, "Runtime": "python3.7", "Tags": [ @@ -18,22 +20,26 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": ["sts:AssumeRole"], + "Action": [ + "sts:AssumeRole" + ], "Effect": "Allow", "Principal": { - "Service": ["lambda.amazonaws.com"] + "Service": [ + "lambda.amazonaws.com" + ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -44,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -65,190 +71,152 @@ } ] } - } - }, - "MyAuthFn": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": ["MyAuthFnRole", "Arn"] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "MyAuthFnRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": ["sts:AssumeRole"], - "Effect": "Allow", - "Principal": { - "Service": ["lambda.amazonaws.com"] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission" }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { - "openapi": "3.0.1", + "components": { + "securitySchemes": { + "AWS_IAM": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authtype": "awsSigv4" + }, + "LambdaAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerPayloadFormatVersion": 1.0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": { + "Fn::GetAtt": [ + "MyAuthFn", + "Arn" + ] + } + } + ] + }, + "type": "request" + } + }, + "MyOauth2Authorizer": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.header.Authorization", + "jwtConfiguration": { + "audience": [ + "audience1", + "audience2" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, + "openapi": "3.0.1", "paths": { - "/hello": { - "get": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "LambdaAuth": [] + } + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/hello": { + "get": { "responses": {}, "security": [ { "LambdaAuth": [] } - ] - }, - "put": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "post": { "responses": {}, "security": [ { - "MyOauth2Authorizer": ["scope"] + "LambdaAuth": [] } - ] - }, - "post": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + }, + "put": { "responses": {}, "security": [ { - "LambdaAuth": [] + "MyOauth2Authorizer": [ + "scope" + ] } - ] - } - }, - "/hello-aws-iam-auth": { - "get": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, + } + } + }, + "/hello-aws-iam-auth": { + "get": { "responses": {}, "security": [ { "AWS_IAM": [] } - ] - } - }, - "$default": { - "x-amazon-apigateway-any-method": { + ], "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - }, - "isDefaultRoute": true, - "responses": {}, - "security": [ - { - "LambdaAuth": [] - } - ] - } - } - }, - "components": { - "securitySchemes": { - "AWS_IAM": { - "type": "apiKey", - "name": "Authorization", - "in": "header", - "x-amazon-apigateway-authtype": "awsSigv4" - }, - "LambdaAuth": { - "type": "apiKey", - "name": "Unused", - "in": "header", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": { - "Fn::GetAtt": ["MyAuthFn", "Arn"] - } - } - ] - }, - "authorizerPayloadFormatVersion": 1.0 - } - }, - "MyOauth2Authorizer": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "jwtConfiguration": { - "audience": ["audience1", "audience2"], - "issuer": "https://www.example.com/v1/connect/oidc" - }, - "identitySource": "$request.header.Authorization", - "type": "jwt" } } } @@ -268,22 +236,76 @@ } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" }, "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", "Properties": { "ApiId": { "Ref": "MyApi" }, + "AutoDeploy": true, "StageName": "$default", "Tags": { "Tag1": "value1", "Tag2": "value2", "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyAuthFn": { + "Properties": { + "Code": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyAuthFnRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyAuthFnRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "AutoDeploy": true - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/http_api_with_cors.json b/tests/translator/output/http_api_with_cors.json index a24a91009a..80ae359410 100644 --- a/tests/translator/output/http_api_with_cors.json +++ b/tests/translator/output/http_api_with_cors.json @@ -2,243 +2,243 @@ "Conditions": { "C1": { "Fn::Equals": [ - true, + true, true ] } - }, + }, "Resources": { - "MyApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "$default": { - "x-amazon-apigateway-any-method": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} - } - } - }, - "x-amazon-apigateway-cors": { - "Fn::If": [ - "C1", - { - "allowHeaders": [ - "x-apigateway-header" - ], - "allowMethods": [ - "GET" - ], - "allowOrigins": [ - "https://foo.com" - ], - "exposeHeaders": [ - "x-amzn-header" - ] - }, - "AWS::NoValue" - ] - }, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, "HttpApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "index.handler", "Code": { "ZipFile": "exports.handler = async (event) => {\n console.log(\"Hello from MyAuthFunction\")\n return {\n statusCode: 200,\n body: JSON.stringify(event),\n headers: {}\n }\n}\n" - }, + }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "HttpApiFunctionRole", + "HttpApiFunctionRole", "Arn" ] - }, - "Runtime": "nodejs12.x", + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "HttpApiFunctionImplicitApiPermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionSimpleCasePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "MyApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "MyApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { "$default": { "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + } + } } } - }, + }, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" + } + ], "x-amazon-apigateway-cors": { "Fn::If": [ - "C1", + "C1", { "allowHeaders": [ "x-apigateway-header" - ], + ], "allowMethods": [ "GET" - ], + ], "allowOrigins": [ "https://foo.com" - ], + ], "exposeHeaders": [ "x-amzn-header" ] - }, + }, "AWS::NoValue" ] - }, - "openapi": "3.0.1", + } + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "ServerlessHttpApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } + } + } + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } - ] + ], + "x-amazon-apigateway-cors": { + "Fn::If": [ + "C1", + { + "allowHeaders": [ + "x-apigateway-header" + ], + "allowMethods": [ + "GET" + ], + "allowOrigins": [ + "https://foo.com" + ], + "exposeHeaders": [ + "x-amzn-header" + ] + }, + "AWS::NoValue" + ] + } + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/http_api_with_custom_domain_route53_multiple.json b/tests/translator/output/http_api_with_custom_domain_route53_multiple.json index 1be40930c5..4027452a35 100644 --- a/tests/translator/output/http_api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/http_api_with_custom_domain_route53_multiple.json @@ -1,255 +1,255 @@ { - "Resources": { - "MyApi1": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } - }, - "ApiGatewayDomainNameV25fe29fe649": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.one.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, - "MyApi1ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi1" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV25fe29fe649" - }, - "Stage": { - "Ref": "MyApi1ApiGatewayDefaultStage" - } - } - }, - "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "abc123456", - "RecordSets": [ - { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV23fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV23fd2dbd8f8", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.three.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV241bfc7f9c4", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV241bfc7f9c4", - "RegionalDomainName" - ] - } - } - } - ] + "Resources": { + "ApiGatewayDomainNameV23fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "ApiGatewayDomainNameV241bfc7f9c4": { + "Properties": { + "DomainName": "admin.three.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "ApiGatewayDomainNameV25fe29fe649": { + "Properties": { + "DomainName": "admin.one.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyApi1": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi1ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi1" }, - "MyApi1ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi1" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi1ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi1" }, - "MyApi2": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV25fe29fe649" }, - "ApiGatewayDomainNameV23fd2dbd8f8": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.two.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } + "Stage": { + "Ref": "MyApi1ApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApi2": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi2ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" }, - "MyApi2ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV23fd2dbd8f8" - }, - "Stage": { - "Ref": "MyApi2ApiGatewayDefaultStage" - } - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi2ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi2" }, - "MyApi2ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi2" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV23fd2dbd8f8" }, - "MyApi3": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } + "Stage": { + "Ref": "MyApi2ApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyApi3": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyApi3ApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyApi3" }, - "ApiGatewayDomainNameV241bfc7f9c4": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.three.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyApi3ApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyApi3" }, - "MyApi3ApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyApi3" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV241bfc7f9c4" - }, - "Stage": { - "Ref": "MyApi3ApiGatewayDefaultStage" - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV241bfc7f9c4" }, - "MyApi3ApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyApi3" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "Stage": { + "Ref": "MyApi3ApiGatewayDefaultStage" } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "RecordSetGroup370194ff6e": { + "Properties": { + "HostedZoneId": "abc123456", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV23fd2dbd8f8", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV23fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV241bfc7f9c4", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV241bfc7f9c4", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.three.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/http_api_with_null_path.json b/tests/translator/output/http_api_with_null_path.json index db515b15b9..86cfb48723 100644 --- a/tests/translator/output/http_api_with_null_path.json +++ b/tests/translator/output/http_api_with_null_path.json @@ -1,122 +1,122 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", - "Resources": { - "EXAMPLEPARTIALLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "EXAMPLEPARTIALLambdaRole", - "Arn" - ] - }, - "Runtime": "python3.9", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } - }, - "EXAMPLEPARTIALLambdaRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", + "Resources": { + "EXAMPLEPARTIALGateway": { + "Properties": { + "Body": { + "openapi": "3.0.1", + "paths": { + "/my/route": { + "post": { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EXAMPLEPARTIALLambda.Arn}/invocations" + } } } - ] + } }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "tags": [ { - "Key": "lambda:createdBy", - "Value": "SAM" + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } ] } }, - "EXAMPLEPARTIALLambdaPostRequestPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "EXAMPLEPARTIALLambda" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/my/route", - { - "__ApiId__": { - "Ref": "EXAMPLEPARTIALGateway" - }, - "__Stage__": "*" - } - ] + "Type": "AWS::ApiGatewayV2::Api" + }, + "EXAMPLEPARTIALGatewayApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "EXAMPLEPARTIALGateway" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "EXAMPLEPARTIALLambda": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "EXAMPLEPARTIALLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.9", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "EXAMPLEPARTIALLambdaPostRequestPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "EXAMPLEPARTIALLambda" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/my/route", + { + "__ApiId__": { + "Ref": "EXAMPLEPARTIALGateway" + }, + "__Stage__": "*" + } + ] } }, - "EXAMPLEPARTIALGateway": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "openapi": "3.0.1", - "paths": { - "/my/route": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${EXAMPLEPARTIALLambda.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - } - } - }, - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" + "Type": "AWS::Lambda::Permission" + }, + "EXAMPLEPARTIALLambdaRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] } - ] + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } - } + ] }, - "EXAMPLEPARTIALGatewayApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "EXAMPLEPARTIALGateway" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } - } + "Type": "AWS::IAM::Role" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/implicit_and_explicit_api_with_conditions.json b/tests/translator/output/implicit_and_explicit_api_with_conditions.json index cc3e91e86a..27cd5818a0 100644 --- a/tests/translator/output/implicit_and_explicit_api_with_conditions.json +++ b/tests/translator/output/implicit_and_explicit_api_with_conditions.json @@ -11,331 +11,68 @@ } ] }, - "explicithello2condition": { + "explicithello1condition": { "Fn::Equals": [ true, false ] }, - "implicithello1condition": { + "explicithello2condition": { "Fn::Equals": [ true, false ] }, - "implicithello2condition": { + "implicithello1condition": { "Fn::Equals": [ true, false ] }, - "explicithello1condition": { + "implicithello2condition": { "Fn::Equals": [ true, false ] } }, + "Description": "A template to test for API condition handling with a mix of explicit and implicit api events.", "Resources": { - "explicithello2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "explicithello2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "explicithello2condition" - }, - "implicithello2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "implicithello2condition" - }, - "explicithello1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "explicithello1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "explicithello1condition" - }, - "explicitapiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "explicitapiDeployment9fcb053eda" - }, - "RestApiId": { - "Ref": "explicitapi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentfa2ce19a90" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "explicithello1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "explicithello1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "explicitapi" - } - } - ] - } - }, - "Condition": "explicithello1condition" - }, - "implicithello2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "implicithello2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "implicithello2condition" - }, - "implicithello1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "implicithello1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "implicithello1condition" - }, - "explicithello2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "explicithello2condition" - }, - "implicithello1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "implicithello1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "implicithello1condition" - }, - "explicithello2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "explicithello2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "explicitapi" - } - } - ] - } - }, - "Condition": "explicithello2condition" - }, - "ServerlessRestApiDeploymentfa2ce19a90": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: fa2ce19a90f37f90f1ece14a3dfcef1fed1f1a6a", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "explicitapi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/explicit/hello2": { + "/implicit/hello1": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { "get": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "explicithello2condition", + "implicithello1condition", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello2.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -348,30 +85,30 @@ } ] }, - "/explicit/hello1": { + "/implicit/hello2": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { "get": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "explicithello1condition", + "implicithello2condition", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello1.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -387,106 +124,67 @@ }, "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" }, - "implicithello2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", + "ServerlessRestApiDeploymentfa2ce19a90": { + "Condition": "ServerlessRestApiCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "implicithello2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "implicithello2condition" - }, - "explicithello1Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } + "Description": "RestApi deployment id: fa2ce19a90f37f90f1ece14a3dfcef1fed1f1a6a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" }, - "Condition": "explicithello1condition" + "Type": "AWS::ApiGateway::Deployment" }, - "explicitapiDeployment9fcb053eda": { - "Type": "AWS::ApiGateway::Deployment", + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentfa2ce19a90" + }, "RestApiId": { - "Ref": "explicitapi" + "Ref": "ServerlessRestApi" }, - "Description": "RestApi deployment id: 9fcb053edaaf92e1c6366f31270d2fb87b370240", - "StageName": "Stage" - } + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "explicitapi": { "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/implicit/hello1": { + "/explicit/hello1": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { "get": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "implicithello1condition", + "explicithello1condition", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello1.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello1.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -499,30 +197,30 @@ } ] }, - "/implicit/hello2": { + "/explicit/hello2": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { "get": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "implicithello2condition", + "explicithello2condition", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${implicithello2.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${explicithello2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -539,22 +237,237 @@ "swagger": "2.0" } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::ApiGateway::RestApi" }, - "implicithello1Role": { - "Type": "AWS::IAM::Role", + "explicitapiDeployment9fcb053eda": { + "Properties": { + "Description": "RestApi deployment id: 9fcb053edaaf92e1c6366f31270d2fb87b370240", + "RestApiId": { + "Ref": "explicitapi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "explicitapiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "explicitapiDeployment9fcb053eda" + }, + "RestApiId": { + "Ref": "explicitapi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "explicithello1": { + "Condition": "explicithello1condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "explicithello1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "explicithello1ApiEventPermissionProd": { + "Condition": "explicithello1condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "explicithello1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello1", + { + "__ApiId__": { + "Ref": "explicitapi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "explicithello1Role": { + "Condition": "explicithello1condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "explicithello2": { + "Condition": "explicithello2condition", "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "explicithello2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "explicithello2ApiEventPermissionProd": { + "Condition": "explicithello2condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "explicithello2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/explicit/hello2", + { + "__ApiId__": { + "Ref": "explicitapi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "explicithello2Role": { + "Condition": "explicithello2condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "implicithello1": { + "Condition": "implicithello1condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "implicithello1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "implicithello1ApiEventPermissionProd": { + "Condition": "implicithello1condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "implicithello1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello1", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "implicithello1Role": { + "Condition": "implicithello1condition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -567,11 +480,98 @@ ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "implicithello2": { + "Condition": "implicithello2condition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "implicithello2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "implicithello2ApiEventPermissionProd": { + "Condition": "implicithello2condition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "implicithello2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/implicit/hello2", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } }, - "Condition": "implicithello1condition" + "Type": "AWS::Lambda::Permission" + }, + "implicithello2Role": { + "Condition": "implicithello2condition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "A template to test for API condition handling with a mix of explicit and implicit api events." + } } diff --git a/tests/translator/output/implicit_api.json b/tests/translator/output/implicit_api.json index 6eb61200b8..b92f84f212 100644 --- a/tests/translator/output/implicit_api.json +++ b/tests/translator/output/implicit_api.json @@ -1,284 +1,282 @@ { "Resources": { - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RestApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "RestApiFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "RestApiFunctionCompleteItemPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "GetHtmlFunction" - }, + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment127e3fb911" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "RestApiFunctionGetListPermissionProd": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment127e3fb911": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d", - "StageName": "Stage" - } - }, - "RestApiFunctionGetListPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" } - } - }, - "RestApiFunctionCompleteItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment127e3fb911": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment127e3fb911" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/implicit_api_deletion_policy_precedence.json b/tests/translator/output/implicit_api_deletion_policy_precedence.json index 025e047358..f82fa898f1 100644 --- a/tests/translator/output/implicit_api_deletion_policy_precedence.json +++ b/tests/translator/output/implicit_api_deletion_policy_precedence.json @@ -1,18 +1,16 @@ { "Resources": { - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", + "GetHtmlFunction": { + "DeletionPolicy": "Retain", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "todo_list.zip" }, - "Handler": "index.restapi", + "Handler": "index.gethtml", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "GetHtmlFunctionRole", "Arn" ] }, @@ -23,15 +21,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function", + "UpdateReplacePolicy": "Retain" }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", + "GetHtmlFunctionGetHtmlPermissionProd": { + "DeletionPolicy": "Retain", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/{proxy++}", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission", + "UpdateReplacePolicy": "Retain" + }, + "GetHtmlFunctionRole": { + "DeletionPolicy": "Retain", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -44,11 +64,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" ], "Tags": [ { @@ -56,12 +77,37 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role", + "UpdateReplacePolicy": "Retain" + }, + "RestApiFunction": { + "DeletionPolicy": "Delete", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function", + "UpdateReplacePolicy": "Retain" }, "RestApiFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", "DeletionPolicy": "Delete", - "UpdateReplacePolicy": "Retain", "Properties": { "Action": "lambda:InvokeFunction", "FunctionName": { @@ -79,40 +125,14 @@ } ] } - } - }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::Lambda::Permission", + "UpdateReplacePolicy": "Retain" }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", + "RestApiFunctionRole": { + "DeletionPolicy": "Delete", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -125,11 +145,12 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" ], "Tags": [ { @@ -137,89 +158,66 @@ "Value": "SAM" } ] - } - }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", - "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", - "Properties": { - "Action": "lambda:InvokeFunction", - "FunctionName": { - "Ref": "GetHtmlFunction" - }, - "Principal": "apigateway.amazonaws.com", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/{proxy++}", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - }, - "__Stage__": "*" - } - ] - } - } + }, + "Type": "AWS::IAM::Role", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "Body": { - "swagger": "2.0", "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { - "/{proxy+}": { + "/{proxy++}": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } }, - "/{proxy++}": { + "/{proxy+}": { "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "type": "aws_proxy", "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } } - } + }, + "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApiDeploymentbeaf67e605": { - "Type": "AWS::ApiGateway::Deployment", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "Description": "RestApi deployment id: beaf67e605cdfc82f45c51fa5f8d9552af2ca0c6", "RestApiId": { "Ref": "ServerlessRestApi" }, "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment", + "UpdateReplacePolicy": "Retain" }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "DeletionPolicy": "Retain", - "UpdateReplacePolicy": "Retain", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeploymentbeaf67e605" @@ -228,7 +226,9 @@ "Ref": "ServerlessRestApi" }, "StageName": "Prod" - } + }, + "Type": "AWS::ApiGateway::Stage", + "UpdateReplacePolicy": "Retain" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/implicit_api_with_auth_and_conditions_max.json b/tests/translator/output/implicit_api_with_auth_and_conditions_max.json index d83d1eb908..03838ccf88 100644 --- a/tests/translator/output/implicit_api_with_auth_and_conditions_max.json +++ b/tests/translator/output/implicit_api_with_auth_and_conditions_max.json @@ -1,34 +1,18 @@ { "Conditions": { - "ServerlessRestApiCondition": { - "Fn::Or": [ - { - "Condition": "FunctionCondition" - }, - { - "Condition": "FunctionCondition2" - }, - { - "Condition": "FunctionCondition3" - }, - { - "Condition": "FunctionCondition4" - }, - { - "Condition": "FunctionCondition5" - }, - { - "Condition": "FunctionCondition6" - } + "FunctionCondition": { + "Fn::Equals": [ + true, + false ] }, - "FunctionCondition6": { + "FunctionCondition2": { "Fn::Equals": [ true, false ] }, - "FunctionCondition5": { + "FunctionCondition3": { "Fn::Equals": [ true, false @@ -40,20 +24,23 @@ false ] }, - "FunctionCondition3": { + "FunctionCondition5": { "Fn::Equals": [ true, false ] }, - "FunctionCondition2": { + "FunctionCondition6": { "Fn::Equals": [ true, false ] }, - "ServerlessRestApiSLASHusersPathCondition": { + "ServerlessRestApiCondition": { "Fn::Or": [ + { + "Condition": "FunctionCondition" + }, { "Condition": "FunctionCondition2" }, @@ -71,159 +58,156 @@ } ] }, - "FunctionCondition": { - "Fn::Equals": [ - true, - false + "ServerlessRestApiSLASHusersPathCondition": { + "Fn::Or": [ + { + "Condition": "FunctionCondition2" + }, + { + "Condition": "FunctionCondition3" + }, + { + "Condition": "FunctionCondition4" + }, + { + "Condition": "FunctionCondition5" + }, + { + "Condition": "FunctionCondition6" + } ] } }, "Resources": { - "MyFunction4": { - "Type": "AWS::Lambda::Function", + "MyFunction": { + "Condition": "FunctionCondition", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction4Role", + "MyFunctionRole", "Arn" ] }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition4" + "Type": "AWS::Lambda::Function" }, - "MyFunction6": { - "Type": "AWS::Lambda::Function", + "MyFunction2": { + "Condition": "FunctionCondition2", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ - "MyFunction6Role", + "MyFunction2Role", "Arn" ] }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction2Role": { + "Condition": "FunctionCondition2", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition6" + "Type": "AWS::IAM::Role" }, "MyFunction2WithCognitoMultipleUserPoolsAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "Condition": "FunctionCondition2", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { "Ref": "MyFunction2" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/users", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "FunctionCondition2" + "Type": "AWS::Lambda::Permission" }, "MyFunction3": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition3", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, - "Role": { - "Fn::GetAtt": [ - "MyFunction3Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "FunctionCondition3" - }, - "MyFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, "Role": { "Fn::GetAtt": [ - "MyFunction2Role", + "MyFunction3Role", "Arn" ] }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition2" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentcbc79073ff" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Function" }, - "MyFunction5Role": { - "Type": "AWS::IAM::Role", + "MyFunction3Role": { + "Condition": "FunctionCondition3", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -236,67 +220,71 @@ ] } } - ] - } - }, - "Condition": "FunctionCondition5" - }, - "MyFunction2Role": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction3WithLambdaTokenAuthorizerPermissionProd": { + "Condition": "FunctionCondition3", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" } ] } }, - "Condition": "FunctionCondition2" + "Type": "AWS::Lambda::Permission" }, - "ServerlessRestApiDeploymentcbc79073ff": { - "Type": "AWS::ApiGateway::Deployment", + "MyFunction4": { + "Condition": "FunctionCondition4", "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" }, - "Description": "RestApi deployment id: cbc79073ff900d53c3f67ea223640210914a672c", - "StageName": "Stage" + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunction4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Function" }, "MyFunction4Role": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition4", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -309,19 +297,51 @@ ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyFunction4WithLambdaTokenAuthorizerPermissionProd": { + "Condition": "FunctionCondition4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] } }, - "Condition": "FunctionCondition4" + "Type": "AWS::Lambda::Permission" }, "MyFunction5": { - "Type": "AWS::Lambda::Function", + "Condition": "FunctionCondition5", "Properties": { - "Handler": "index.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" }, + "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "MyFunction5Role", @@ -331,27 +351,17 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition5" + "Type": "AWS::Lambda::Function" }, - "MyFunction6Role": { - "Type": "AWS::IAM::Role", + "MyFunction5Role": { + "Condition": "FunctionCondition5", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -364,66 +374,71 @@ ] } } - ] - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "FunctionCondition6" + "Type": "AWS::IAM::Role" }, - "ServerlessRestApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", + "MyFunction5WithLambdaRequestAuthorizerPermissionProd": { + "Condition": "FunctionCondition5", "Properties": { "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction5" + }, "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", { "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" }, - "MyFunctionWithNoAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunction6": { + "Condition": "FunctionCondition6", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "MyFunction6Role", + "Arn" ] - } - }, - "Condition": "FunctionCondition" - }, - "MyFunction3Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunction6Role": { + "Condition": "FunctionCondition6", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -436,131 +451,47 @@ ] } } - ] - } - }, - "Condition": "FunctionCondition3" - }, - "MyFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "MyFunctionRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] }, - "Condition": "FunctionCondition" + "Type": "AWS::IAM::Role" }, - "MyFunction4WithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunction6WithDefaultAuthorizerPermissionProd": { + "Condition": "FunctionCondition6", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFunction4" + "Ref": "MyFunction6" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PATCH/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition4" - }, - "ServerlessRestApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "ServerlessRestApiCondition" - }, - "MyFunction5WithLambdaRequestAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction5" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/DELETE/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "FunctionCondition5" - }, - "ServerlessRestApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", { "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", + "Condition": "FunctionCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -573,64 +504,52 @@ ] } } - ] - } - }, - "Condition": "FunctionCondition" - }, - "MyFunction3WithLambdaTokenAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction3" + ], + "Version": "2012-10-17" }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/users", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "FunctionCondition3" + "Type": "AWS::IAM::Role" }, - "MyFunction6WithDefaultAuthorizerPermissionProd": { - "Type": "AWS::Lambda::Permission", + "MyFunctionWithNoAuthorizerPermissionProd": { + "Condition": "FunctionCondition", "Properties": { "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", "FunctionName": { - "Ref": "MyFunction6" + "Ref": "MyFunction" }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/PUT/users", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } }, - "Condition": "FunctionCondition6" + "Type": "AWS::Lambda::Permission" }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/": { @@ -641,6 +560,12 @@ "Fn::If": [ "FunctionCondition", { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -655,13 +580,7 @@ } ] } - }, - "security": [ - { - "NONE": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -678,158 +597,158 @@ "Fn::If": [ "ServerlessRestApiSLASHusersPathCondition", { - "put": { + "delete": { "Fn::If": [ - "FunctionCondition6", + "FunctionCondition5", { + "responses": {}, + "security": [ + { + "MyLambdaRequestAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition6", + "FunctionCondition5", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction6.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction5.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "api_key": [] - }, - { - "MyCognitoAuth": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "patch": { + "get": { "Fn::If": [ - "FunctionCondition4", + "FunctionCondition3", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition4", + "FunctionCondition3", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction4.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction3.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "post": { + "patch": { "Fn::If": [ - "FunctionCondition2", + "FunctionCondition4", { + "responses": {}, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition2", + "FunctionCondition4", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction2.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction4.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyCognitoAuthMultipleUserPools": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "get": { + "post": { "Fn::If": [ - "FunctionCondition3", + "FunctionCondition2", { + "responses": {}, + "security": [ + { + "MyCognitoAuthMultipleUserPools": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition3", + "FunctionCondition2", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction3.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction2.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaTokenAuth": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] }, - "delete": { + "put": { "Fn::If": [ - "FunctionCondition5", + "FunctionCondition6", { + "responses": {}, + "security": [ + { + "api_key": [] + }, + { + "MyCognitoAuth": [] + } + ], "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "FunctionCondition5", + "FunctionCondition6", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction5.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction6.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "security": [ - { - "MyLambdaRequestAuth": [] - } - ], - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -843,39 +762,41 @@ ] } }, - "swagger": "2.0", "securityDefinitions": { - "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "MyCognitoAuth": { "in": "header", + "name": "MyAuthorizationHeader", "type": "apiKey", - "name": "Authorization", "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - } + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" }, - "x-amazon-apigateway-authtype": "custom" + "x-amazon-apigateway-authtype": "cognito_user_pools" }, - "api_key": { + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", "type": "apiKey", - "name": "x-api-key", - "in": "header" + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" }, "MyLambdaRequestAuth": { "in": "header", - "type": "apiKey", "name": "Unused", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "request", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", "authorizerUri": { "Fn::Sub": [ "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", @@ -884,29 +805,17 @@ } ] }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" }, "x-amazon-apigateway-authtype": "custom" }, - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, "MyLambdaTokenAuth": { "in": "header", - "type": "apiKey", "name": "MyCustomAuthHeader", + "type": "apiKey", "x-amazon-apigateway-authorizer": { - "type": "token", + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", "authorizerResultTtlInSeconds": 20, "authorizerUri": { "Fn::Sub": [ @@ -916,29 +825,120 @@ } ] }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" + "identityValidationExpression": "mycustomauthexpression", + "type": "token" }, "x-amazon-apigateway-authtype": "custom" }, - "MyCognitoAuthMultipleUserPools": { + "MyLambdaTokenAuthNoneFunctionInvokeRole": { "in": "header", + "name": "Authorization", "type": "apiKey", - "name": "MyAuthorizationHeader2", "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", + { + "__FunctionArn__": "arn:aws" + } + ] + }, + "type": "token" }, - "x-amazon-apigateway-authtype": "cognito_user_pools" + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - } + }, + "swagger": "2.0" } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentcbc79073ff": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Description": "RestApi deployment id: cbc79073ff900d53c3f67ea223640210914a672c", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiMyLambdaRequestAuthAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiMyLambdaTokenAuthAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentcbc79073ff" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/implicit_api_with_many_conditions.json b/tests/translator/output/implicit_api_with_many_conditions.json index 5d9b800cf2..e3cb2b3d5b 100644 --- a/tests/translator/output/implicit_api_with_many_conditions.json +++ b/tests/translator/output/implicit_api_with_many_conditions.json @@ -1,49 +1,49 @@ { "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "Cond5": { + "Cond": { "Fn::Equals": [ true, false ] }, - "Cond4": { + "Cond1": { "Fn::Equals": [ true, false ] }, - "Cond7": { + "Cond2": { "Fn::Equals": [ true, false ] }, - "Cond6": { + "Cond3": { "Fn::Equals": [ true, false ] }, - "Cond1": { + "Cond4": { "Fn::Equals": [ true, false ] }, - "Cond3": { + "Cond5": { "Fn::Equals": [ true, false ] }, - "Cond2": { + "Cond6": { "Fn::Equals": [ true, false ] }, - "Cond9": { + "Cond7": { "Fn::Equals": [ true, false @@ -55,7 +55,13 @@ false ] }, - "Cond": { + "Cond9": { + "Fn::Equals": [ + true, + false + ] + }, + "MyCondition": { "Fn::Equals": [ true, false @@ -105,12 +111,6 @@ } ] }, - "MyCondition": { - "Fn::Equals": [ - true, - false - ] - }, "ServerlessRestApiSLASHsubPathCondition": { "Fn::Or": [ { @@ -122,934 +122,28 @@ ] } }, + "Description": "A template to test for implicit API condition handling.", "Resources": { - "helloworld7ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld7" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond7" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentd229cbabc1" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "ServerlessRestApiCondition" - }, - "helloworld1Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond1" - }, - "helloworld7": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld7Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond7" - }, - "helloworld6": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld6Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond6" - }, - "helloworldRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond" - }, - "helloworld4": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld4Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond4" - }, - "helloworld3": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld3Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond3" - }, - "helloworld2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond2" - }, - "helloworld1": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld1Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond1" - }, - "helloworld9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld9Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond9" - }, - "helloApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "hello" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "MyCondition" - }, - "helloworld2ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond2" - }, - "ServerlessRestApiDeploymentd229cbabc1": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: d229cbabc195ae9406a1e544dedb556864eb05b0", - "StageName": "Stage" - }, - "Condition": "ServerlessRestApiCondition" - }, - "helloworld3ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond3" - }, - "helloworld1ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld1" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond1" - }, - "helloworld8": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld8Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond8" - }, - "helloworld6ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld6" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond6" - }, - "helloworld4Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond4" - }, - "helloworldApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond" - }, - "helloworld9Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld5ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld5" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond5" - }, - "helloworld8ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld8" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond8" - }, - "helloRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "MyCondition" - }, - "helloworld8Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond8" - }, - "helloworld": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworldRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond" - }, - "helloworld5Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond5" - }, - "hello": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "MyCondition" - }, - "helloworld5": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld5Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond5" - }, - "helloworld9ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld9" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld6Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond6" - }, - "helloworld7Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond7" - }, - "helloworld2Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond2" - }, - "helloworld3Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - }, - "Condition": "Cond3" - }, - "helloworld4ApiEventPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld4" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - }, - "Condition": "Cond4" - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + "ServerlessRestApi": { + "Condition": "ServerlessRestApiCondition", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } + }, + "version": "1.0" }, "paths": { "/sub": { "Fn::If": [ "ServerlessRestApiSLASHsubPathCondition", { - "post": { - "Fn::If": [ - "Cond", - { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::If": [ - "Cond", - { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - }, "get": { "Fn::If": [ "MyCondition", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1064,80 +158,33 @@ } ] } - }, - "responses": {} - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "/sub8": { - "Fn::If": [ - "Cond8", - { - "post": { - "Fn::If": [ - "Cond8", - { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::If": [ - "Cond8", - { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" } ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "/sub9": { - "Fn::If": [ - "Cond9", - { + }, "post": { "Fn::If": [ - "Cond9", + "Cond", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond9", + "Cond", { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld.Arn}/invocations" }, { "Ref": "AWS::NoValue" } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1158,6 +205,7 @@ "Fn::If": [ "Cond1", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1172,8 +220,7 @@ } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1194,6 +241,7 @@ "Fn::If": [ "Cond2", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1208,8 +256,7 @@ } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1230,6 +277,7 @@ "Fn::If": [ "Cond3", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1244,8 +292,7 @@ } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1266,6 +313,7 @@ "Fn::If": [ "Cond4", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1280,8 +328,7 @@ } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1302,6 +349,7 @@ "Fn::If": [ "Cond5", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1316,8 +364,7 @@ } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1338,6 +385,7 @@ "Fn::If": [ "Cond6", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1352,8 +400,7 @@ } ] } - }, - "responses": {} + } }, { "Ref": "AWS::NoValue" @@ -1374,6 +421,7 @@ "Fn::If": [ "Cond7", { + "responses": {}, "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -1388,8 +436,79 @@ } ] } - }, - "responses": {} + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "/sub8": { + "Fn::If": [ + "Cond8", + { + "post": { + "Fn::If": [ + "Cond8", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "Cond8", + { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "/sub9": { + "Fn::If": [ + "Cond9", + { + "post": { + "Fn::If": [ + "Cond9", + { + "responses": {}, + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::If": [ + "Cond9", + { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + }, + { + "Ref": "AWS::NoValue" + } + ] + } + } }, { "Ref": "AWS::NoValue" @@ -1402,12 +521,893 @@ } ] } - }, - "swagger": "2.0" + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentd229cbabc1": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "Description": "RestApi deployment id: d229cbabc195ae9406a1e544dedb556864eb05b0", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "ServerlessRestApiCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentd229cbabc1" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "hello": { + "Condition": "MyCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloApiEventPermissionProd": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "hello" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloRole": { + "Condition": "MyCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld": { + "Condition": "Cond", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworldRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1": { + "Condition": "Cond1", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld1Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1ApiEventPermissionProd": { + "Condition": "Cond1", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1Role": { + "Condition": "Cond1", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld2": { + "Condition": "Cond2", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld2ApiEventPermissionProd": { + "Condition": "Cond2", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld2Role": { + "Condition": "Cond2", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld3": { + "Condition": "Cond3", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld3Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld3ApiEventPermissionProd": { + "Condition": "Cond3", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld3" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld3Role": { + "Condition": "Cond3", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld4": { + "Condition": "Cond4", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld4ApiEventPermissionProd": { + "Condition": "Cond4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld4Role": { + "Condition": "Cond4", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld5": { + "Condition": "Cond5", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld5Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld5ApiEventPermissionProd": { + "Condition": "Cond5", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld5" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld5Role": { + "Condition": "Cond5", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld6": { + "Condition": "Cond6", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld6ApiEventPermissionProd": { + "Condition": "Cond6", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld6" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld6Role": { + "Condition": "Cond6", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld7": { + "Condition": "Cond7", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld7Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld7ApiEventPermissionProd": { + "Condition": "Cond7", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld7" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld7Role": { + "Condition": "Cond7", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld8": { + "Condition": "Cond8", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld8Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld8ApiEventPermissionProd": { + "Condition": "Cond8", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld8" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] } }, - "Condition": "ServerlessRestApiCondition" + "Type": "AWS::Lambda::Permission" + }, + "helloworld8Role": { + "Condition": "Cond8", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld9": { + "Condition": "Cond9", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld9Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld9ApiEventPermissionProd": { + "Condition": "Cond9", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld9" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld9Role": { + "Condition": "Cond9", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworldApiEventPermissionProd": { + "Condition": "Cond", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworldRole": { + "Condition": "Cond", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } - }, - "Description": "A template to test for implicit API condition handling." + } } diff --git a/tests/translator/output/implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/implicit_api_with_serverless_rest_api_resource.json index 17e8437c57..b92f84f212 100644 --- a/tests/translator/output/implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/implicit_api_with_serverless_rest_api_resource.json @@ -1,282 +1,282 @@ { "Resources": { - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", + "GetHtmlFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "GetHtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { "Key": "lambda:createdBy", "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "GetHtmlFunctionGetHtmlPermissionProd": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "GetHtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "GetHtmlFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "RestApiFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "RestApiFunctionAddItemPermissionProd": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/add", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunctionGetHtmlPermissionProd": { - "Type": "AWS::Lambda::Permission", + "RestApiFunctionCompleteItemPermissionProd": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "GetHtmlFunction" - }, + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*/*", + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessRestApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment127e3fb911" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } + }, + "Type": "AWS::Lambda::Permission" }, - "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", + "RestApiFunctionGetListPermissionProd": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.gethtml", - "Role": { - "Fn::GetAtt": [ - "GetHtmlFunctionRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "RestApiFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", + { + "__ApiId__": { + "Ref": "ServerlessRestApi" + }, + "__Stage__": "*" + } ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/AmazonDynamoDBReadOnlyAccess" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Handler": "index.restapi", - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ServerlessRestApiDeployment127e3fb911": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d", - "StageName": "Stage" - } - }, - "RestApiFunctionGetListPermissionProd": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/getlist", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" } - } - }, - "RestApiFunctionCompleteItemPermissionProd": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment127e3fb911": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "RestApiFunction" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/complete", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessRestApi" - } - } - ] - } - } + "Description": "RestApi deployment id: 127e3fb91142ab1ddc5f5446adb094442581a90d", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment127e3fb911" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" } } } diff --git a/tests/translator/output/implicit_http_api.json b/tests/translator/output/implicit_http_api.json index 146970cf60..dd928fbc71 100644 --- a/tests/translator/output/implicit_http_api.json +++ b/tests/translator/output/implicit_http_api.json @@ -1,275 +1,275 @@ { "Resources": { - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "HttpApiFunction": { "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunction2": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "HttpApiFunction2Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "HttpApiFunction2Basic2Permission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/basic2", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] } - } - }, - "HttpApiFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "HttpApiFunction2PathParametersPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HttpApiFunction2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "HttpApiFunction2Role": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "HttpApiFunction2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "HttpApiFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HttpApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "HttpApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "HttpApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, - "HttpApiFunction2": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "HttpApiFunction2Role", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/basic2": { - "post": { + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" + } + } } - }, - "/get/{something}/with/{params}": { + }, + "/basic": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {}, - "parameters": [ - { - "required": true, - "name": "something", - "in": "path" - }, - { - "required": true, - "name": "params", - "in": "path" + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" } - ] + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/basic2": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" + } + } } - }, - "/basic": { + }, + "/get/{something}/with/{params}": { "post": { + "parameters": [ + { + "in": "path", + "name": "something", + "required": true + }, + { + "in": "path", + "name": "params", + "required": true + } + ], + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HttpApiFunction2.Arn}/invocations" + } + } } } - }, - "openapi": "3.0.1", + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } - }, - "HttpApiFunction2PathParametersPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/get/*/with/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - } - }, - "HttpApiFunction2Basic2Permission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "HttpApiFunction2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/basic2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" } - } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/implicit_http_api_auth_and_simple_case.json b/tests/translator/output/implicit_http_api_auth_and_simple_case.json index 4f518881f6..88c74e43a5 100644 --- a/tests/translator/output/implicit_http_api_auth_and_simple_case.json +++ b/tests/translator/output/implicit_http_api_auth_and_simple_case.json @@ -1,230 +1,230 @@ { "Resources": { - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", + "RestApiFunction": { "Properties": { - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "AutoDeploy": true, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - } - }, + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "todo_list.zip" + }, + "Handler": "index.restapi", + "Role": { + "Fn::GetAtt": [ + "RestApiFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "RestApiFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.restapi", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "todo_list.zip" - }, - "Role": { - "Fn::GetAtt": [ - "RestApiFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "RestApiFunctionSimpleCasePermission": { - "Type": "AWS::Lambda::Permission", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "RestApiFunction" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", "Properties": { "Body": { + "components": { + "securitySchemes": { + "oauth2Auth": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/defaultauth": { - "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + "$default": { + "x-amazon-apigateway-any-method": { + "isDefaultRoute": true, + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - }, - "/oauth2": { - "post": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + } + } + } + }, + "/defaultauth": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + } + } } - }, - "$default": { - "x-amazon-apigateway-any-method": { + }, + "/noneauth": { + "post": { + "responses": {}, + "security": [ + { + "NONE": [] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, + } + } + } + }, + "/oauth2": { + "post": { + "responses": {}, "security": [ { "oauth2Auth": [ "scope4" ] } - ], - "responses": {} - } - }, - "/noneauth": { - "post": { + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, - "security": [ - { - "NONE": [] } - ], - "responses": {} + } } - }, + }, "/scope3": { "post": { - "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" - }, - "payloadFormatVersion": "2.0" - }, + "responses": {}, "security": [ { "oauth2Auth": [ "scope3" ] } - ], - "responses": {} - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2Auth": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" + ], + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } } } } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/implicit_http_api_with_many_conditions.json b/tests/translator/output/implicit_http_api_with_many_conditions.json index c4b9618b8c..5fa816737e 100644 --- a/tests/translator/output/implicit_http_api_with_many_conditions.json +++ b/tests/translator/output/implicit_http_api_with_many_conditions.json @@ -1,1506 +1,1506 @@ { - "AWSTemplateFormatVersion": "2010-09-09", + "AWSTemplateFormatVersion": "2010-09-09", "Conditions": { - "Cond5": { + "Cond": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond4": { + }, + "Cond1": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond7": { + }, + "Cond2": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond6": { + }, + "Cond3": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond1": { + }, + "Cond4": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond3": { + }, + "Cond5": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond2": { + }, + "Cond6": { "Fn::Equals": [ - true, + true, false ] - }, - "ServerlessHttpApiCondition": { - "Fn::Or": [ - { - "Condition": "MyCondition" - }, - { - "Condition": "ServerlessHttpApiCondition1" - } - ] - }, - "Cond9": { + }, + "Cond7": { "Fn::Equals": [ - true, + true, false ] - }, + }, "Cond8": { "Fn::Equals": [ - true, + true, false ] - }, - "Cond": { + }, + "Cond9": { + "Fn::Equals": [ + true, + false + ] + }, + "MyCondition": { "Fn::Equals": [ - true, + true, false ] - }, + }, + "ServerlessHttpApiCondition": { + "Fn::Or": [ + { + "Condition": "MyCondition" + }, + { + "Condition": "ServerlessHttpApiCondition1" + } + ] + }, "ServerlessHttpApiCondition1": { "Fn::Or": [ { "Condition": "Cond" - }, + }, { "Condition": "Cond1" - }, + }, { "Condition": "Cond2" - }, + }, { "Condition": "Cond3" - }, + }, { "Condition": "Cond4" - }, + }, { "Condition": "Cond5" - }, + }, { "Condition": "Cond6" - }, + }, { "Condition": "Cond7" - }, + }, { "Condition": "Cond8" - }, + }, { "Condition": "Cond9" } ] - }, - "MyCondition": { - "Fn::Equals": [ - true, - false - ] } - }, - "Description": "A template to test for implicit HttpApi condition handling.", + }, + "Description": "A template to test for implicit HttpApi condition handling.", "Resources": { - "helloworld9HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld9" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond9" - }, - "helloworld9Role": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - }, - "Condition": "Cond9" - }, - "helloworld2HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld2" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond2" - }, "ServerlessHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", + "Condition": "ServerlessHttpApiCondition", "Properties": { "Body": { + "components": { + "securitySchemes": { + "oauth2": { + "type": "oauth2", + "x-amazon-apigateway-authorizer": { + "identitySource": "$request.querystring.param", + "jwtConfiguration": { + "audience": [ + "MyApi" + ], + "issuer": "https://www.example.com/v1/connect/oidc" + }, + "type": "jwt" + } + } + } + }, "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, + "openapi": "3.0.1", "paths": { - "/hello/again": { + "$default": { "Fn::If": [ - "Cond", + "Cond", { - "get": { + "x-amazon-apigateway-any-method": { "Fn::If": [ - "Cond", + "Cond", { + "isDefaultRoute": true, + "responses": {}, + "security": [ + { + "oauth2": [ + "scope4" + ] + } + ], "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "Cond", { "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub": { + }, + "/hello/again": { "Fn::If": [ - "MyCondition", + "Cond", { "get": { "Fn::If": [ - "MyCondition", + "Cond", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "MyCondition", + "Cond", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub8": { + }, + "/sub": { "Fn::If": [ - "Cond8", + "MyCondition", { - "post": { + "get": { "Fn::If": [ - "Cond8", + "MyCondition", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond8", + "MyCondition", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${hello.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub9": { + }, + "/sub1": { "Fn::If": [ - "Cond9", + "Cond1", { "post": { "Fn::If": [ - "Cond9", + "Cond1", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond9", + "Cond1", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "$default": { + }, + "/sub2": { "Fn::If": [ - "Cond", + "Cond2", { - "x-amazon-apigateway-any-method": { + "post": { "Fn::If": [ - "Cond", + "Cond2", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond", + "Cond2", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1099.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "isDefaultRoute": true, - "security": [ - { - "oauth2": [ - "scope4" - ] } - ], - "responses": {} - }, + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub1": { + }, + "/sub3": { "Fn::If": [ - "Cond1", + "Cond3", { "post": { "Fn::If": [ - "Cond1", + "Cond3", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond1", + "Cond3", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld1.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub2": { + }, + "/sub4": { "Fn::If": [ - "Cond2", + "Cond4", { "post": { "Fn::If": [ - "Cond2", + "Cond4", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond2", + "Cond4", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld2.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub3": { + }, + "/sub5": { "Fn::If": [ - "Cond3", + "Cond5", { "post": { "Fn::If": [ - "Cond3", + "Cond5", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond3", + "Cond5", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld3.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub4": { + }, + "/sub6": { "Fn::If": [ - "Cond4", + "Cond6", { "post": { "Fn::If": [ - "Cond4", + "Cond6", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond4", + "Cond6", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld4.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub5": { + }, + "/sub7": { "Fn::If": [ - "Cond5", + "Cond7", { "post": { "Fn::If": [ - "Cond5", + "Cond7", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond5", + "Cond7", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld5.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub6": { + }, + "/sub8": { "Fn::If": [ - "Cond6", + "Cond8", { "post": { "Fn::If": [ - "Cond6", + "Cond8", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond6", + "Cond8", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld6.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld8.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] - }, - "/sub7": { + }, + "/sub9": { "Fn::If": [ - "Cond7", + "Cond9", { "post": { "Fn::If": [ - "Cond7", + "Cond9", { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "payloadFormatVersion": "2.0", + "type": "aws_proxy", "uri": { "Fn::If": [ - "Cond7", + "Cond9", { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld7.Arn}/invocations" - }, + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${helloworld9.Arn}/invocations" + }, { "Ref": "AWS::NoValue" } ] - }, - "payloadFormatVersion": "2.0" - }, - "responses": {} - }, + } + } + }, { "Ref": "AWS::NoValue" } ] } - }, + }, { "Ref": "AWS::NoValue" } ] } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "oauth2": { - "type": "oauth2", - "x-amazon-apigateway-authorizer": { - "identitySource": "$request.querystring.param", - "type": "jwt", - "jwtConfiguration": { - "audience": [ - "MyApi" - ], - "issuer": "https://www.example.com/v1/connect/oidc" - } - } - } - } - }, + }, "tags": [ { - "name": "httpapi:createdBy", + "name": "httpapi:createdBy", "x-amazon-apigateway-tag-value": "SAM" } ] } - }, - "Condition": "ServerlessHttpApiCondition" - }, - "helloworld6HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "ServerlessHttpApiApiGatewayDefaultStage": { + "Condition": "ServerlessHttpApiCondition", + "Properties": { + "ApiId": { + "Ref": "ServerlessHttpApi" + }, + "AutoDeploy": true, + "RouteSettings": { + "$default": { + "Fn::If": [ + "Cond", + { + "ThrottlingBurstLimit": 200 + }, + { + "Ref": "AWS::NoValue" + } + ] + }, + "GET /sub": { + "Fn::If": [ + "MyCondition", + { + "ThrottlingBurstLimit": 200 + }, + { + "Ref": "AWS::NoValue" + } + ] + } + }, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "hello": { + "Condition": "MyCondition", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloHttpApiEventPermission": { + "Condition": "MyCondition", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld6" - }, + "Ref": "hello" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond6" - }, - "helloworld1Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloRole": { + "Condition": "MyCondition", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond1" - }, - "helloworld7": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld1": { + "Condition": "Cond1", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld7Role", + "helloworld1Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond7" - }, - "helloworld6": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld6Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond6" - }, - "helloworld5": { - "Type": "AWS::Lambda::Function", + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1099": { + "Condition": "Cond", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld5Role", + "helloworld1099Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond5" - }, - "helloworld1099Role": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld1099HttpApiEventPermission": { + "Condition": "Cond", "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1099" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1099Role": { + "Condition": "Cond", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond" - }, - "helloworld3": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld1HttpApiEventPermission": { + "Condition": "Cond1", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld3Role", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld1" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond3" - }, - "helloworld2": { - "Type": "AWS::Lambda::Function", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld1Role": { + "Condition": "Cond1", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld2Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond2" - }, - "helloworld1": { - "Type": "AWS::Lambda::Function", + ] + }, + "Type": "AWS::IAM::Role" + }, + "helloworld2": { + "Condition": "Cond2", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld1Role", + "helloworld2Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond1" - }, - "helloworld9": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld9Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond9" - }, - "hello": { - "Type": "AWS::Lambda::Function", + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld2HttpApiEventPermission": { + "Condition": "Cond2", "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloRole", - "Arn" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld2" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub2", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "MyCondition" - }, - "helloRole": { - "Type": "AWS::IAM::Role", + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld2Role": { + "Condition": "Cond2", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "MyCondition" - }, - "helloworld7HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld7" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond7" - }, - "helloHttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld3": { + "Condition": "Cond3", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "hello" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/sub", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld3Role", + "Arn" ] - } - }, - "Condition": "MyCondition" - }, - "helloworld1HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld3HttpApiEventPermission": { + "Condition": "Cond3", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld1" - }, + "Ref": "helloworld3" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub1", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond1" - }, - "helloworld5Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld3Role": { + "Condition": "Cond3", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond5" - }, + }, + "Type": "AWS::IAM::Role" + }, + "helloworld4": { + "Condition": "Cond4", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld4Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld4HttpApiEventPermission": { + "Condition": "Cond4", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld4" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "helloworld4Role": { - "Type": "AWS::IAM::Role", + "Condition": "Cond4", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond4" - }, - "helloworld1099HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld5": { + "Condition": "Cond5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld1099" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld5Role", + "Arn" ] - } - }, - "Condition": "Cond" - }, + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "helloworld5HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "Cond5", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "helloworld5" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub5", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond5" - }, - "helloworld7Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld5Role": { + "Condition": "Cond5", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond7" - }, - "helloworld2Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld6": { + "Condition": "Cond6", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld6Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld6HttpApiEventPermission": { + "Condition": "Cond6", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld6" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub6", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld6Role": { + "Condition": "Cond6", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond2" - }, - "helloworld8Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld7": { + "Condition": "Cond7", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "helloworld7Role", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld7HttpApiEventPermission": { + "Condition": "Cond7", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "helloworld7" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub7", + { + "__ApiId__": { + "Ref": "ServerlessHttpApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld7Role": { + "Condition": "Cond7", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond8" - }, - "helloworld4": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld8": { + "Condition": "Cond8", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld4Role", + "helloworld8Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond4" - }, - "helloworld1099": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "helloworld1099Role", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond" - }, + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "helloworld8HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + "Condition": "Cond8", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "helloworld8" - }, + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub8", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond8" - }, - "ServerlessHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "AutoDeploy": true, - "ApiId": { - "Ref": "ServerlessHttpApi" - }, - "RouteSettings": { - "GET /sub": { - "Fn::If": [ - "MyCondition", - { - "ThrottlingBurstLimit": 200 - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "$default": { - "Fn::If": [ - "Cond", - { - "ThrottlingBurstLimit": 200 - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - } - }, - "Condition": "ServerlessHttpApiCondition" - }, - "helloworld3Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld8Role": { + "Condition": "Cond8", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond3" - }, - "helloworld8": { - "Type": "AWS::Lambda::Function", + }, + "Type": "AWS::IAM::Role" + }, + "helloworld9": { + "Condition": "Cond9", "Properties": { "Code": { "ZipFile": "exports.handler = async () => \u2018Hello World!'\n" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 128, - "Handler": "index.handler", + }, + "Handler": "index.handler", + "MemorySize": 128, "Role": { "Fn::GetAtt": [ - "helloworld8Role", + "helloworld9Role", "Arn" ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - }, - "Condition": "Cond8" - }, - "helloworld4HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, + "helloworld9HttpApiEventPermission": { + "Condition": "Cond9", "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { - "Ref": "helloworld4" - }, + "Ref": "helloworld9" + }, + "Principal": "apigateway.amazonaws.com", "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub4", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub9", { - "__Stage__": "*", "__ApiId__": { "Ref": "ServerlessHttpApi" - } + }, + "__Stage__": "*" } ] } - }, - "Condition": "Cond4" - }, - "helloworld6Role": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Permission" + }, + "helloworld9Role": { + "Condition": "Cond9", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "Cond6" - }, - "helloworld3HttpApiEventPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "helloworld3" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/sub3", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "ServerlessHttpApi" - } - } - ] - } - }, - "Condition": "Cond3" + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/inline_precedence.json b/tests/translator/output/inline_precedence.json index 6ea4caaf01..423d7d2918 100644 --- a/tests/translator/output/inline_precedence.json +++ b/tests/translator/output/inline_precedence.json @@ -1,10 +1,30 @@ { "Resources": { + "HelloWorldFunction": { + "Properties": { + "Code": { + "ZipFile": "\"def lambda_handler():\n pass\"\n" + }, + "Handler": "index.lambda_handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "python3.8", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "HelloWorldFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -17,40 +37,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "HelloWorldFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.lambda_handler", - "Code": { - "ZipFile": "\"def lambda_handler():\n pass\"\n" - }, - "Role": { - "Fn::GetAtt": [ - "HelloWorldFunctionRole", - "Arn" - ] - }, - "Runtime": "python3.8", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/intrinsic_functions.json b/tests/translator/output/intrinsic_functions.json index 3b8fa89ccb..f4eee1a16e 100644 --- a/tests/translator/output/intrinsic_functions.json +++ b/tests/translator/output/intrinsic_functions.json @@ -8,14 +8,14 @@ } }, "Parameters": { - "CodeKey": { - "Default": "key", - "Type": "String" - }, "CodeBucket": { "Default": "sam-demo-bucket", "Type": "String" }, + "CodeKey": { + "Default": "key", + "Type": "String" + }, "FunctionName": { "Default": "MySuperFunctionName", "Type": "String" @@ -24,165 +24,106 @@ "Default": "SomeName", "Type": "String" }, + "RoleFieldName": { + "Default": "Role", + "Type": "String" + }, "TracingConfigParam": { "Default": "PassThrough", "Type": "String" - }, - "RoleFieldName": { - "Type": "String", - "Default": "Role" } }, "Resources": { - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" - }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } - }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, - "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "DeadLetterConfig": { - "TargetArn": { - "Fn::GetAtt": [ - "SqsDlqQueue", - "Arn" - ] - } - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MySqsDlqLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7" - } - }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", + "Condition": "TrueCondition", "Properties": { "BodyS3Location": { - "Version": "myversion", "Bucket": "mybucket", - "Key": "mykey" + "Key": "mykey", + "Version": 3 } }, - "Condition": "TrueCondition" + "Type": "AWS::ApiGateway::RestApi" }, - "MyExplicitApiDeployment7145dd00ce": { - "Type": "AWS::ApiGateway::Deployment", + "ApiWithExplicitS3UriDeployment7ab7044581": { + "Condition": "TrueCondition", "Properties": { + "Description": "RestApi deployment id: 7ab7044581d53db4957e668f336b462f099db4af", "RestApiId": { - "Ref": "MyExplicitApi" + "Ref": "ApiWithExplicitS3Uri" }, - "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", "StageName": "Stage" - } + }, + "Type": "AWS::ApiGateway::Deployment" }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", + "ApiWithExplicitS3UridevStage": { + "Condition": "TrueCondition", + "Properties": { + "DeploymentId": { + "Ref": "ApiWithExplicitS3UriDeployment7ab7044581" + }, + "RestApiId": { + "Ref": "ApiWithExplicitS3Uri" + }, + "StageName": "dev" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "DynamoDBFunction": { "Properties": { - "Handler": "stream.ddb_handler", "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" }, + "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", + "DynamoDBFunctionRole", "Arn" ] }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "DynamoDBFunctionMyDDBStream": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ], - "Policies": [ - { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Ref": "SnsDlqQueue" - }, - "Effect": "Allow" + "BatchSize": 200, + "EventSourceArn": { + "Fn::GetAtt": [ + "MyTable", + "StreamArn" + ] + }, + "FilterCriteria": { + "Fn::Select": [ + "1", + [ + {}, + { + "Filters": { + "Pattern": "{\"value\": \"b\"}" } - ] - } - } - ], + } + ] + ] + }, + "FunctionName": { + "Ref": "DynamoDBFunction" + }, + "StartingPosition": "LATEST" + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "DynamoDBFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -195,21 +136,33 @@ ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, - "MyOtherFunction": { - "Type": "AWS::Lambda::Function", + "FunctionWithExplicitS3Uri": { "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" + "S3Bucket": "mybucket", + "S3Key": "mykey", + "S3ObjectVersion": "MyVersion" }, - "Handler": "hello.handler", + "Handler": "stream.ddb_handler", "Role": { "Fn::GetAtt": [ - "MyOtherFunctionRole", + "FunctionWithExplicitS3UriRole", "Arn" ] }, @@ -220,13 +173,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyOtherFunctionRole": { - "Type": "AWS::IAM::Role", + "FunctionWithExplicitS3UriRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -239,7 +191,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -250,10 +203,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "FunctionWithValidGetAttAndRef": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -275,16 +228,59 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MyFunction": { - "Type": "AWS::Lambda::Function", + "MyExplicitApi": { "Properties": { - "TracingConfig": { - "Mode": { - "Ref": "TracingConfigParam" - } + "BodyS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "swagger.yaml" + }, + "Name": { + "Ref": "MyExplicitApiName" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyExplicitApiDeployment7145dd00ce": { + "Properties": { + "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", + "RestApiId": { + "Ref": "MyExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyExplicitApidevStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyExplicitApiDeployment7145dd00ce" + }, + "RestApiId": { + "Ref": "MyExplicitApi" }, + "StageName": "dev", + "Variables": { + "FunctionName": { + "Fn::Sub": "${MyFunction}" + }, + "Var2": { + "Fn::Join": [ + "join ", + [ + "some value ", + "with some other value" + ] + ] + } + } + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyFunction": { + "Properties": { "Code": { "S3Bucket": { "Ref": "CodeBucket" @@ -305,12 +301,6 @@ "FunctionName": { "Fn::Sub": "${FunctionName}" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": { "Fn::Sub": [ "${filename}.handler", @@ -333,17 +323,48 @@ "4.3" ] ] + }, + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "TracingConfig": { + "Mode": { + "Ref": "TracingConfigParam" + } } - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionWithExplicitS3UriRole": { - "Type": "AWS::IAM::Role", + "MyFunctionMyApiPermissiondev": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "MyFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": { + "Ref": "MyExplicitApi" + }, + "__Stage__": "*" + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyNewRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ "sts:AssumeRole" ], "Effect": "Allow", @@ -353,48 +374,56 @@ ] } } - ] + ], + "Version": "2012-10-17" }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "cloudwatch:*", + "logs:*" + ], + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "lambdaRole" } ] - } - }, - "ApiWithExplicitS3UriDeployment7ab7044581": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" - }, - "Description": "RestApi deployment id: 7ab7044581d53db4957e668f336b462f099db4af", - "StageName": "Stage" }, - "Condition": "TrueCondition" + "Type": "AWS::IAM::Role" }, - "ApiWithExplicitS3UridevStage": { - "Type": "AWS::ApiGateway::Stage", + "MyOtherFunction": { "Properties": { - "DeploymentId": { - "Ref": "ApiWithExplicitS3UriDeployment7ab7044581" + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" }, - "RestApiId": { - "Ref": "ApiWithExplicitS3Uri" + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MyOtherFunctionRole", + "Arn" + ] }, - "StageName": "dev" + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] }, - "Condition": "TrueCondition" + "Type": "AWS::Lambda::Function" }, - "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", + "MyOtherFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -407,22 +436,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySnsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -433,12 +462,6 @@ "Ref": "SnsDlqQueue" } }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -446,73 +469,64 @@ "Arn" ] }, - "Runtime": "python2.7" - } + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MyExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", + "MySnsDlqLambdaFunctionRole": { "Properties": { - "BodyS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "swagger.yaml" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Name": { - "Ref": "MyExplicitApiName" - } - } - }, - "MyTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "StreamSpecification": { - "StreamViewType": "NEW_IMAGE" - }, - "AttributeDefinitions": [ + "Policies": [ { - "AttributeName": "id", - "AttributeType": "S" + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": { + "Ref": "SnsDlqQueue" + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], - "ProvisionedThroughput": { - "WriteCapacityUnits": 5, - "ReadCapacityUnits": 5 - } - } - }, - "SnsDlqQueue": { - "Type": "AWS::SNS::Topic" - }, - "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "stream.ddb_handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Role": { - "Fn::GetAtt": [ - "DynamoDBFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "MySqsDlqLambdaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -526,12 +540,6 @@ ] } }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "Handler": "index.handler", "Role": { "Fn::GetAtt": [ @@ -539,117 +547,19 @@ "Arn" ] }, - "Runtime": "python2.7" - } - }, - "MyExplicitApidevStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyExplicitApiDeployment7145dd00ce" - }, - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "Variables": { - "FunctionName": { - "Fn::Sub": "${MyFunction}" - }, - "Var2": { - "Fn::Join": [ - "join ", - [ - "some value ", - "with some other value" - ] - ] - } - }, - "StageName": "dev" - } - }, - "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 200, - "FunctionName": { - "Ref": "DynamoDBFunction" - }, - "StartingPosition": "LATEST", - "EventSourceArn": { - "Fn::GetAtt": [ - "MyTable", - "StreamArn" - ] - }, - "FilterCriteria": { - "Fn::Select": [ - "1", - [ - {}, - { - "Filters": { - "Pattern": "{\"value\": \"b\"}" - } - } - ] - ] - } - } - }, - "FunctionWithExplicitS3Uri": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "stream.ddb_handler", - "Code": { - "S3Bucket": "mybucket", - "S3Key": "mykey", - "S3ObjectVersion": "MyVersion" - }, - "Role": { - "Fn::GetAtt": [ - "FunctionWithExplicitS3UriRole", - "Arn" - ] - }, "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "SqsDlqQueue": { - "Type": "AWS::SQS::Queue" - }, - "MyExplicitApiDeployment7145dd00ce": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyExplicitApi" - }, - "Description": "RestApi deployment id: 7145dd00cea59b4a62b4d7855add490c587f3f62", - "StageName": "Stage" - } - }, - "ApiWithExplicitS3Uri": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "BodyS3Location": { - "Version": 3, - "Bucket": "mybucket", - "Key": "mykey" - } }, - "Condition": "TrueCondition" + "Type": "AWS::Lambda::Function" }, "MySqsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -662,145 +572,70 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Policies": [ { - "PolicyName": "DeadLetterQueuePolicy", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ "SqsDlqQueue", "Arn" ] - }, - "Effect": "Allow" + } } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "DeadLetterQueuePolicy" } ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "MySnsDlqLambdaFunctionRole": { - "Type": "AWS::IAM::Role", + "MyTable": { "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Policies": [ + "AttributeDefinitions": [ { - "PolicyName": "DeadLetterQueuePolicy", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sns:Publish", - "Resource": { - "Ref": "SnsDlqQueue" - }, - "Effect": "Allow" - } - ] - } + "AttributeName": "id", + "AttributeType": "S" } ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "MyNewRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + "KeySchema": [ { - "PolicyName": "lambdaRole", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "cloudwatch:*", - "logs:*" - ], - "Resource": "*", - "Effect": "Allow" - } - ] - } + "AttributeName": "id", + "KeyType": "HASH" } ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "MyFunctionMyApiPermissiondev": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": { - "Ref": "MyFunction" + "ProvisionedThroughput": { + "ReadCapacityUnits": 5, + "WriteCapacityUnits": 5 }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", - { - "__Stage__": "*", - "__ApiId__": { - "Ref": "MyExplicitApi" - } - } - ] + "StreamSpecification": { + "StreamViewType": "NEW_IMAGE" } - } + }, + "Type": "AWS::DynamoDB::Table" + }, + "SnsDlqQueue": { + "Type": "AWS::SNS::Topic" + }, + "SqsDlqQueue": { + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/iot_rule.json b/tests/translator/output/iot_rule.json index 0600c3b825..379c78ae31 100644 --- a/tests/translator/output/iot_rule.json +++ b/tests/translator/output/iot_rule.json @@ -1,31 +1,79 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Parameters": {}, + "AWSTemplateFormatVersion": "2010-09-09", + "Parameters": {}, "Resources": { + "IoTRuleFunc": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Description": "Created by SAM", + "Handler": "index.handler", + "MemorySize": 1024, + "Role": { + "Fn::GetAtt": [ + "IoTRuleFuncRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ], + "Timeout": 3 + }, + "Type": "AWS::Lambda::Function" + }, "IoTRuleFuncMyIoTRule": { - "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { - "AwsIotSqlVersion": "beta", "Actions": [ { "Lambda": { "FunctionArn": { "Fn::GetAtt": [ - "IoTRuleFunc", + "IoTRuleFunc", "Arn" ] } } } - ], - "RuleDisabled": false, + ], + "AwsIotSqlVersion": "beta", + "RuleDisabled": false, "Sql": "SELECT * FROM 'topic/test'" } - } - }, + }, + "Type": "AWS::IoT::TopicRule" + }, + "IoTRuleFuncMyIoTRulePermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "IoTRuleFunc" + }, + "Principal": "iot.amazonaws.com", + "SourceAccount": { + "Fn::Sub": "${AWS::AccountId}" + }, + "SourceArn": { + "Fn::Sub": [ + "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + { + "RuleName": { + "Ref": "IoTRuleFuncMyIoTRule" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, "IoTRuleFuncMyOtherIoTRule": { - "Type": "AWS::IoT::TopicRule", "Properties": { "TopicRulePayload": { "Actions": [ @@ -33,55 +81,32 @@ "Lambda": { "FunctionArn": { "Fn::GetAtt": [ - "IoTRuleFunc", + "IoTRuleFunc", "Arn" ] } } } - ], - "RuleDisabled": false, + ], + "RuleDisabled": false, "Sql": "SELECT * FROM 'topic/test'" } - } - }, - "IoTRuleFuncMyIoTRulePermission": { - "Type": "AWS::Lambda::Permission", + }, + "Type": "AWS::IoT::TopicRule" + }, + "IoTRuleFuncMyOtherIoTRulePermission": { "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", + "Action": "lambda:InvokeFunction", "FunctionName": { "Ref": "IoTRuleFunc" - }, - "SourceArn": { - "Fn::Sub": [ - "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", - { - "RuleName": { - "Ref": "IoTRuleFuncMyIoTRule" - } - } - ] - } - } - }, - "IoTRuleFuncMyOtherIoTRulePermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", + }, + "Principal": "iot.amazonaws.com", "SourceAccount": { "Fn::Sub": "${AWS::AccountId}" - }, - "Principal": "iot.amazonaws.com", - "FunctionName": { - "Ref": "IoTRuleFunc" - }, + }, "SourceArn": { "Fn::Sub": [ - "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", + "arn:aws:iot:${AWS::Region}:${AWS::AccountId}:rule/${RuleName}", { "RuleName": { "Ref": "IoTRuleFuncMyOtherIoTRule" @@ -89,63 +114,38 @@ } ] } - } - }, - "IoTRuleFunc": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Description": "Created by SAM", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "MemorySize": 1024, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "IoTRuleFuncRole", - "Arn" - ] - }, - "Timeout": 3, - "Runtime": "nodejs12.x" - } - }, + }, + "Type": "AWS::Lambda::Permission" + }, "IoTRuleFuncRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/kinesis_intrinsics.json b/tests/translator/output/kinesis_intrinsics.json index c7802de792..8263bad824 100644 --- a/tests/translator/output/kinesis_intrinsics.json +++ b/tests/translator/output/kinesis_intrinsics.json @@ -1,168 +1,168 @@ { - "Conditions": { - "TrueCondition": { - "Fn::Equals": [ - true, - true - ] - }, - "FalseCondition": { - "Fn::Equals": [ - true, - false + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + }, + "TrueCondition": { + "Fn::Equals": [ + true, + true + ] + } + }, + "Parameters": { + "FunctionResponseTypesValue": { + "Default": "ReportBatchItemFailures", + "Type": "String" + }, + "IntValue": { + "Default": 50, + "Type": "Number" + }, + "StartingPositionValue": { + "Default": "LATEST", + "Type": "String" + }, + "StringValue": { + "Default": "us-east-1", + "Type": "String" + } + }, + "Resources": { + "MyLambdaFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "stream.zip" + }, + "Handler": "index.handler", + "MemorySize": 128, + "Role": { + "Fn::GetAtt": [ + "MyLambdaFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } ] - } - }, - "Resources": { - "MyLambdaFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + }, + "Type": "AWS::Lambda::Function" + }, + "MyLambdaFunctionKinesisStream": { + "Properties": { + "BatchSize": { + "Ref": "IntValue" + }, + "BisectBatchOnFunctionError": { + "Fn::If": [ + "FalseCondition", + true, + false + ] + }, + "Enabled": { + "Fn::If": [ + "TrueCondition", + true, + false + ] + }, + "EventSourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":kinesis:", + { + "Ref": "AWS::Region" + }, + ":", { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } + "Ref": "AWS::AccountId" + }, + ":stream/", + { + "Ref": "MyStream" } ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } ] - } - }, - "MyLambdaFunctionKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "MaximumBatchingWindowInSeconds": { - "Ref": "IntValue" - }, - "FunctionName": { - "Ref": "MyLambdaFunction" - }, - "MaximumRecordAgeInSeconds": { - "Ref": "IntValue" - }, - "FunctionResponseTypes": [ - { - "Ref": "FunctionResponseTypesValue" - } - ], - "BatchSize": { - "Ref": "IntValue" - }, - "TumblingWindowInSeconds": { - "Ref": "IntValue" - }, - "Enabled": { - "Fn::If": [ - "TrueCondition", - true, - false - ] - }, - "EventSourceArn": { - "Fn::Join": [ - "", - [ - "arn:", - { - "Ref": "AWS::Partition" - }, - ":kinesis:", - { - "Ref": "AWS::Region" - }, - ":", - { - "Ref": "AWS::AccountId" - }, - ":stream/", - { - "Ref": "MyStream" - } - ] - ] - }, - "StartingPosition": { - "Ref": "StartingPositionValue" - }, - "ParallelizationFactor": { - "Ref": "IntValue" - }, - "MaximumRetryAttempts": { - "Ref": "IntValue" - }, - "BisectBatchOnFunctionError": { - "Fn::If": [ - "FalseCondition", - true, - false - ] + }, + "FunctionName": { + "Ref": "MyLambdaFunction" + }, + "FunctionResponseTypes": [ + { + "Ref": "FunctionResponseTypesValue" } + ], + "MaximumBatchingWindowInSeconds": { + "Ref": "IntValue" + }, + "MaximumRecordAgeInSeconds": { + "Ref": "IntValue" + }, + "MaximumRetryAttempts": { + "Ref": "IntValue" + }, + "ParallelizationFactor": { + "Ref": "IntValue" + }, + "StartingPosition": { + "Ref": "StartingPositionValue" + }, + "TumblingWindowInSeconds": { + "Ref": "IntValue" } - }, - "MyStream": { - "Type": "AWS::Kinesis::Stream", - "Properties": { - "ShardCount": 1 - } - }, - "MyLambdaFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "stream.zip" - }, - "Tags": [ + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "MyLambdaFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } } - ], - "MemorySize": 128, - "Handler": "index.handler", - "Role": { - "Fn::GetAtt": [ - "MyLambdaFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x" - } - } - }, - "Parameters": { - "StringValue": { - "Default": "us-east-1", - "Type": "String" - }, - "IntValue": { - "Default": 50, - "Type": "Number" - }, - "FunctionResponseTypesValue": { - "Default": "ReportBatchItemFailures", - "Type": "String" - }, - "StartingPositionValue": { - "Default": "LATEST", - "Type": "String" - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStream": { + "Properties": { + "ShardCount": 1 + }, + "Type": "AWS::Kinesis::Stream" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/layer_deletion_policy_precedence.json b/tests/translator/output/layer_deletion_policy_precedence.json index 8bb610ad00..f2b1de47a4 100644 --- a/tests/translator/output/layer_deletion_policy_precedence.json +++ b/tests/translator/output/layer_deletion_policy_precedence.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalLayer22b6609c3d": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Retain", "Properties": { "Content": { @@ -9,10 +8,10 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer" - } + }, + "Type": "AWS::Lambda::LayerVersion" }, "MinimalLayer2800a44a445": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Delete", "Properties": { "Content": { @@ -20,10 +19,10 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer2" - } + }, + "Type": "AWS::Lambda::LayerVersion" }, "MinimalLayer3ac07350a04": { - "Type": "AWS::Lambda::LayerVersion", "DeletionPolicy": "Retain", "Properties": { "Content": { @@ -31,7 +30,8 @@ "S3Key": "layer.zip" }, "LayerName": "MinimalLayer3" - } + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/layers_all_properties.json b/tests/translator/output/layers_all_properties.json index a99809489d..51d278acf2 100644 --- a/tests/translator/output/layers_all_properties.json +++ b/tests/translator/output/layers_all_properties.json @@ -1,120 +1,120 @@ { "Outputs": { - "LayerSub": { - "Value": { - "Fn::Sub": "${MyLayerd04062b365}" - } - }, "FunctionAtt": { "Value": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] } - }, - "LayerName": { + }, + "FunctionName": { "Value": { - "Ref": "MyLayerd04062b365" + "Ref": "MyFunction" } - }, + }, "FunctionSub": { "Value": { "Fn::Sub": "${MyFunction}" } - }, - "FunctionName": { + }, + "LayerName": { "Value": { - "Ref": "MyFunction" + "Ref": "MyLayerd04062b365" + } + }, + "LayerSub": { + "Value": { + "Fn::Sub": "${MyLayerd04062b365}" } } - }, + }, "Parameters": { "LayerDeleteParam": { - "Default": "Delete", + "Default": "Delete", "Type": "String" } - }, + }, "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Layers": [ - { - "Ref": "MyLayerd04062b365" - } - ], "Code": { - "S3Bucket": "bucket", + "S3Bucket": "bucket", "S3Key": "key" - }, - "Tags": [ + }, + "Handler": "app.handler", + "Layers": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "MyLayerd04062b365" } - ], - "Handler": "app.handler", + ], "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python3.6" - } - }, - "MyLayerd04062b365": { - "DeletionPolicy": "Delete", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "MyLayer" - } - }, - "MyLayerWithANamefda8c9ec8c": { - "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", - "Properties": { - "Content": { - "S3Bucket": "bucket", - "S3Key": "key" - }, - "LayerName": "DifferentLayerName" - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyLayerWithANamefda8c9ec8c": { + "DeletionPolicy": "Retain", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "DifferentLayerName" + }, + "Type": "AWS::Lambda::LayerVersion" + }, + "MyLayerd04062b365": { + "DeletionPolicy": "Delete", + "Properties": { + "Content": { + "S3Bucket": "bucket", + "S3Key": "key" + }, + "LayerName": "MyLayer" + }, + "Type": "AWS::Lambda::LayerVersion" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/layers_with_intrinsics.json b/tests/translator/output/layers_with_intrinsics.json index f1b63d8a0a..aadcc22443 100644 --- a/tests/translator/output/layers_with_intrinsics.json +++ b/tests/translator/output/layers_with_intrinsics.json @@ -1,167 +1,166 @@ { "Parameters": { "CompatibleArchitecturesList": { - "Type": "CommaDelimitedList", - "Default": "arm64,x86_64" + "Default": "arm64,x86_64", + "Type": "CommaDelimitedList" }, "CompatibleArchitecturesRef": { - "Type": "String", - "Default": "arm64" + "Default": "arm64", + "Type": "String" }, "LayerLicenseInfo": { "Default": "MIT-0 License", "Type": "String" }, - "LayerRuntimeList": { - "Type": "CommaDelimitedList" - }, "LayerNameParam": { "Default": "SomeLayerName", "Type": "String" }, + "LayerRuntimeList": { + "Type": "CommaDelimitedList" + }, "LayerRuntimeRefString": { "Default": "SomeRuntimeName", "Type": "String" } }, "Resources": { - "LayerWithNameIntrinsiccf8baed8b9": { + "LayerWithArchitecturesIntrinsicb79067ee69": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleArchitectures": { + "Ref": "CompatibleArchitecturesList" + }, "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "SomeLayerName" - } + "LayerName": "LayerWithArchitecturesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithRefNameIntrinsicRegion32bf7198a5": { + "LayerWithLicenseIntrinsic965c8d0c9b": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "ap-southeast-1" - } + "LayerName": "LayerWithLicenseIntrinsic", + "LicenseInfo": "MIT-0 License" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSubNameIntrinsicRegiond71326de24": { + "LayerWithMixedListRefRuntimesIntrinsic71fd80f592": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleRuntimes": [ + { + "Ref": "LayerRuntimeString" + }, + "SomeRuntimeNameString" + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": { - "Fn::Sub": "layer-ap-southeast-1" - } - } + "LayerName": "LayerWithMixedListRefRuntimesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithRuntimesIntrinsic1a006faa85": { + "LayerWithNameIntrinsiccf8baed8b9": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithRuntimesIntrinsic", - "CompatibleRuntimes": { - "Ref": "LayerRuntimeList" - } - } + "LayerName": "SomeLayerName" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": { + "LayerWithRefNameIntrinsicRegion32bf7198a5": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleRuntimes": [ - { - "Ref": "LayerRuntimeRefString" - } - ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithSingleListRefRuntimesIntrinsic" + "LayerName": "ap-southeast-1" }, "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithMixedListRefRuntimesIntrinsic71fd80f592": { + "LayerWithRuntimesIntrinsic1a006faa85": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleRuntimes": [ - { - "Ref": "LayerRuntimeString" - }, - "SomeRuntimeNameString" - ], + "CompatibleRuntimes": { + "Ref": "LayerRuntimeList" + }, "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithMixedListRefRuntimesIntrinsic" + "LayerName": "LayerWithRuntimesIntrinsic" }, "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithLicenseIntrinsic965c8d0c9b": { + "LayerWithSingleListRefArchitecturesIntrinsicf8a2807636": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { + "CompatibleArchitectures": [ + { + "Ref": "CompatibleArchitecturesRef" + } + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithLicenseIntrinsic", - "LicenseInfo": "MIT-0 License" - } + "LayerName": "LayerWithSingleListRefArchitecturesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSubNameIntrinsic6e9b477102": { - "Type": "AWS::Lambda::LayerVersion", + "LayerWithSingleListRefRuntimesIntrinsic9d7a72f24a": { "DeletionPolicy": "Retain", "Properties": { + "CompatibleRuntimes": [ + { + "Ref": "LayerRuntimeRefString" + } + ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": { - "Fn::Sub": "layer-SomeLayerName" - } - } + "LayerName": "LayerWithSingleListRefRuntimesIntrinsic" + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithArchitecturesIntrinsicb79067ee69": { + "LayerWithSubNameIntrinsic6e9b477102": { "DeletionPolicy": "Retain", - "Type": "AWS::Lambda::LayerVersion", "Properties": { "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithArchitecturesIntrinsic", - "CompatibleArchitectures": { - "Ref": "CompatibleArchitecturesList" + "LayerName": { + "Fn::Sub": "layer-SomeLayerName" } - } + }, + "Type": "AWS::Lambda::LayerVersion" }, - "LayerWithSingleListRefArchitecturesIntrinsicf8a2807636": { + "LayerWithSubNameIntrinsicRegiond71326de24": { "DeletionPolicy": "Retain", "Properties": { - "CompatibleArchitectures": [ - { - "Ref": "CompatibleArchitecturesRef" - } - ], "Content": { "S3Bucket": "sam-demo-bucket", "S3Key": "layer.zip" }, - "LayerName": "LayerWithSingleListRefArchitecturesIntrinsic" + "LayerName": { + "Fn::Sub": "layer-ap-southeast-1" + } }, "Type": "AWS::Lambda::LayerVersion" } } } - diff --git a/tests/translator/output/mixed_api_with_custom_domain_route53_multiple.json b/tests/translator/output/mixed_api_with_custom_domain_route53_multiple.json index 025997925c..d9a5bb35ac 100644 --- a/tests/translator/output/mixed_api_with_custom_domain_route53_multiple.json +++ b/tests/translator/output/mixed_api_with_custom_domain_route53_multiple.json @@ -1,193 +1,193 @@ { - "AWSTemplateFormatVersion": "2010-09-09", - "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", - "Resources": { - "MyRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "swagger": "2.0" - }, - "Name": "App-Prod-Web", - "Parameters": { - "endpointConfigurationTypes": "REGIONAL" - }, - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "apigateway-2402\nSample SAM Template for apigateway-2402\n", + "Resources": { + "ApiGatewayDomainName3fd2dbd8f8": { + "Properties": { + "DomainName": "admin.two.amazon.com", + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "MyHttpApiApiMapping": { - "Type": "AWS::ApiGatewayV2::ApiMapping", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi" - }, - "DomainName": { - "Ref": "ApiGatewayDomainNameV25fe29fe649" - }, - "Stage": { - "Ref": "MyHttpApiApiGatewayDefaultStage" - } + "RegionalCertificateArn": "arn::cert::abc" + }, + "Type": "AWS::ApiGateway::DomainName" + }, + "ApiGatewayDomainNameV25fe29fe649": { + "Properties": { + "DomainName": "admin.one.amazon.com", + "DomainNameConfigurations": [ + { + "CertificateArn": "arn::cert::abc", + "EndpointType": "REGIONAL" + } + ], + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::DomainName" + }, + "MyHttpApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": {}, + "tags": [ + { + "name": "httpapi:createdBy", + "x-amazon-apigateway-tag-value": "SAM" } + ] + } + }, + "Type": "AWS::ApiGatewayV2::Api" + }, + "MyHttpApiApiGatewayDefaultStage": { + "Properties": { + "ApiId": { + "Ref": "MyHttpApi" }, - "MyRestApiDeployment61887a4eed": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", - "RestApiId": { - "Ref": "MyRestApi" - }, - "StageName": "Stage" - } + "AutoDeploy": true, + "StageName": "$default", + "Tags": { + "httpapi:createdBy": "SAM" + } + }, + "Type": "AWS::ApiGatewayV2::Stage" + }, + "MyHttpApiApiMapping": { + "Properties": { + "ApiId": { + "Ref": "MyHttpApi" }, - "ApiGatewayDomainName3fd2dbd8f8": { - "Type": "AWS::ApiGateway::DomainName", - "Properties": { - "RegionalCertificateArn": "arn::cert::abc", - "DomainName": "admin.two.amazon.com", - "EndpointConfiguration": { - "Types": [ - "REGIONAL" - ] - } - } + "DomainName": { + "Ref": "ApiGatewayDomainNameV25fe29fe649" }, - "ApiGatewayDomainNameV25fe29fe649": { - "Type": "AWS::ApiGatewayV2::DomainName", - "Properties": { - "DomainName": "admin.one.amazon.com", - "DomainNameConfigurations": [ - { - "EndpointType": "REGIONAL", - "CertificateArn": "arn::cert::abc" - } - ], - "Tags": { - "httpapi:createdBy": "SAM" - } - } + "Stage": { + "Ref": "MyHttpApiApiGatewayDefaultStage" + } + }, + "Type": "AWS::ApiGatewayV2::ApiMapping" + }, + "MyRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": {}, + "swagger": "2.0" }, - "MyHttpApi": { - "Type": "AWS::ApiGatewayV2::Api", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": {}, - "openapi": "3.0.1", - "tags": [ - { - "name": "httpapi:createdBy", - "x-amazon-apigateway-tag-value": "SAM" - } - ] - } - } + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] }, - "MyHttpApiApiGatewayDefaultStage": { - "Type": "AWS::ApiGatewayV2::Stage", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi" - }, - "StageName": "$default", - "Tags": { - "httpapi:createdBy": "SAM" - }, - "AutoDeploy": true - } + "Name": "App-Prod-Web", + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyRestApiBasePathMapping": { + "Properties": { + "DomainName": { + "Ref": "ApiGatewayDomainName3fd2dbd8f8" }, - "MyRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyRestApiDeployment61887a4eed" - }, - "RestApiId": { - "Ref": "MyRestApi" - }, - "StageName": "Prod", - "TracingEnabled": true, - "MethodSettings": [ - { - "HttpMethod": "*", - "ResourcePath": "/*", - "LoggingLevel": "Info" - } - ] - } + "RestApiId": { + "Ref": "MyRestApi" }, - "MyRestApiBasePathMapping": { - "Type": "AWS::ApiGateway::BasePathMapping", - "Properties": { - "DomainName": { - "Ref": "ApiGatewayDomainName3fd2dbd8f8" - }, - "RestApiId": { - "Ref": "MyRestApi" - }, - "Stage": { - "Ref": "MyRestApiProdStage" - } - } + "Stage": { + "Ref": "MyRestApiProdStage" + } + }, + "Type": "AWS::ApiGateway::BasePathMapping" + }, + "MyRestApiDeployment61887a4eed": { + "Properties": { + "Description": "RestApi deployment id: 61887a4eed03102402cbaa575b5b1e398b0dc647", + "RestApiId": { + "Ref": "MyRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyRestApiDeployment61887a4eed" + }, + "MethodSettings": [ + { + "HttpMethod": "*", + "LoggingLevel": "Info", + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "MyRestApi" }, - "RecordSetGroup370194ff6e": { - "Type": "AWS::Route53::RecordSetGroup", - "Properties": { - "HostedZoneId": "abc123456", - "RecordSets": [ - { - "Name": "admin.two.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainName3fd2dbd8f8", - "RegionalDomainName" - ] - } - } - }, - { - "Name": "admin.one.amazon.com", - "Type": "A", - "AliasTarget": { - "HostedZoneId": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalHostedZoneId" - ] - }, - "DNSName": { - "Fn::GetAtt": [ - "ApiGatewayDomainNameV25fe29fe649", - "RegionalDomainName" - ] - } - } - } + "StageName": "Prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "RecordSetGroup370194ff6e": { + "Properties": { + "HostedZoneId": "abc123456", + "RecordSets": [ + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalDomainName" ] - } - } + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainName3fd2dbd8f8", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.two.amazon.com", + "Type": "A" + }, + { + "AliasTarget": { + "DNSName": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalDomainName" + ] + }, + "HostedZoneId": { + "Fn::GetAtt": [ + "ApiGatewayDomainNameV25fe29fe649", + "RegionalHostedZoneId" + ] + } + }, + "Name": "admin.one.amazon.com", + "Type": "A" + } + ] + }, + "Type": "AWS::Route53::RecordSetGroup" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json b/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json index 2a4b1979ac..487c58b71b 100644 --- a/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json +++ b/tests/translator/output/no_implicit_api_with_serverless_rest_api_resource.json @@ -1,261 +1,261 @@ { "Resources": { "GetHtmlFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "GetHtmlFunctionRole", + "GetHtmlFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "GetHtmlFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "RestApiFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ + ] + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" ] } } ] } - } - }, + }, + "Type": "AWS::S3::Bucket" + }, "RestApiFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "RestApiFunctionRole", + "RestApiFunctionRole", "Arn" ] - }, - "Runtime": "python3.6", + }, + "Runtime": "python3.6", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Lambda::Function" + }, + "RestApiFunctionRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] - } - }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", "Properties": { "Body": { "info": { - "version": "1.0", "title": { "Ref": "AWS::StackName" - } - }, + }, + "version": "1.0" + }, "paths": { "/add": { "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/complete": { + "post": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" } - }, - "responses": {} + } } - }, + }, "/getlist": { "get": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "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": { + }, + "/{proxy+}": { + "x-amazon-apigateway-any-method": { + "responses": {}, "x-amazon-apigateway-integration": { - "httpMethod": "POST", - "type": "aws_proxy", + "httpMethod": "POST", + "type": "aws_proxy", "uri": { - "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${RestApiFunction.Arn}/invocations" + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetHtmlFunction.Arn}/invocations" } - }, - "responses": {} + } } } - }, + }, "swagger": "2.0" } - } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ThumbnailFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/resource_with_invalid_type.json b/tests/translator/output/resource_with_invalid_type.json index 92cca3173c..4d9d7cfd63 100644 --- a/tests/translator/output/resource_with_invalid_type.json +++ b/tests/translator/output/resource_with_invalid_type.json @@ -1,17 +1,16 @@ { "Resources": { "FunctionInvalid": { - "Type": { - "AWS::Serverless::Function": "invalid_field" - }, "Properties": { "CodeUri": "s3://sam-demo-bucket/member_portal.zip", "Handler": "index.gethtml", "Runtime": "nodejs12.x" + }, + "Type": { + "AWS::Serverless::Function": "invalid_field" } }, "FunctionValid": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -31,13 +30,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "FunctionValidRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -50,7 +48,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -61,7 +60,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3.json b/tests/translator/output/s3.json index da8ce55bcf..44b4fff753 100644 --- a/tests/translator/output/s3.json +++ b/tests/translator/output/s3.json @@ -1,89 +1,91 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_create_remove.json b/tests/translator/output/s3_create_remove.json index 297f014240..d5ce7b398a 100644 --- a/tests/translator/output/s3_create_remove.json +++ b/tests/translator/output/s3_create_remove.json @@ -1,106 +1,110 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { + "BucketEncryption": { + "ServerSideEncryptionConfiguration": [ + { + "ServerSideEncryptionByDefault": { + "SSEAlgorithm": "AES256" + } + } + ] + }, + "BucketName": "BucketNameParameter", "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" - }, + } + }, { + "Event": "s3:ObjectRemoved:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectRemoved:*" + } } ] - }, - "BucketName": "BucketNameParameter", - "BucketEncryption": { - "ServerSideEncryptionConfiguration": [{ - "ServerSideEncryptionByDefault": { - "SSEAlgorithm": "AES256" - } - }] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_existing_lambda_notification_configuration.json b/tests/translator/output/s3_existing_lambda_notification_configuration.json index 35b92f77c8..44b4fff753 100644 --- a/tests/translator/output/s3_existing_lambda_notification_configuration.json +++ b/tests/translator/output/s3_existing_lambda_notification_configuration.json @@ -1,89 +1,91 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_existing_other_notification_configuration.json b/tests/translator/output/s3_existing_other_notification_configuration.json index 425051451f..3ed84e8461 100644 --- a/tests/translator/output/s3_existing_other_notification_configuration.json +++ b/tests/translator/output/s3_existing_other_notification_configuration.json @@ -1,97 +1,97 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } - ], + ], "TopicConfigurations": [ { - "Topic": "my-super-awesome-topic", - "Event": "s3:ObjectRemoved:*" + "Event": "s3:ObjectRemoved:*", + "Topic": "my-super-awesome-topic" } ] } - }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_filter.json b/tests/translator/output/s3_filter.json index 7e377d29ac..a408f186f9 100644 --- a/tests/translator/output/s3_filter.json +++ b/tests/translator/output/s3_filter.json @@ -1,99 +1,101 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectCreated:*", "Filter": { "S3Key": { "Rules": [ { - "Name": "name", + "Name": "name", "Value": "value" } ] } - }, - "Event": "s3:ObjectCreated:*" + }, + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_intrinsics.json b/tests/translator/output/s3_intrinsics.json index 6b5e52f3e3..4f6ad72d13 100644 --- a/tests/translator/output/s3_intrinsics.json +++ b/tests/translator/output/s3_intrinsics.json @@ -15,17 +15,14 @@ }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectCreated:*", "Filter": { "Fn::If": [ "MyCondition", @@ -51,20 +48,57 @@ } ] }, - "Event": "s3:ObjectCreated:*" + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } } ] } }, - "DependsOn": [ - "ThumbnailFunctionImageBucketPermission" - ] + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" }, "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -77,54 +111,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/s3_multiple_events_same_bucket.json b/tests/translator/output/s3_multiple_events_same_bucket.json index 30ec9dbdec..6593fc2c8d 100644 --- a/tests/translator/output/s3_multiple_events_same_bucket.json +++ b/tests/translator/output/s3_multiple_events_same_bucket.json @@ -1,121 +1,124 @@ { "Resources": { - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "ThumbnailFunctionImageBucketCreatesPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketDeletesPermission", "ThumbnailFunctionImageBucketCreatesPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketDeletesPermission", + "ThumbnailFunctionImageBucketCreatesPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { - "Function": { - "Fn::GetAtt": [ - "ThumbnailFunction", - "Arn" - ] - }, + "Event": "s3:ObjectRemoved:*", "Filter": { "S3Key": { "Rules": [ { - "Name": "suffix", + "Name": "suffix", "Value": ".jpg" } ] } - }, - "Event": "s3:ObjectRemoved:*" - }, + }, + "Function": { + "Fn::GetAtt": [ + "ThumbnailFunction", + "Arn" + ] + } + }, { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionImageBucketDeletesPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, + }, + "Type": "AWS::S3::Bucket" + }, "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", + }, + "Handler": "index.generate_thumbails", "Role": { "Fn::GetAtt": [ - "ThumbnailFunctionRole", + "ThumbnailFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketCreatesPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionImageBucketDeletesPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_multiple_functions.json b/tests/translator/output/s3_multiple_functions.json index fc1d479568..db52beec7f 100644 --- a/tests/translator/output/s3_multiple_functions.json +++ b/tests/translator/output/s3_multiple_functions.json @@ -1,99 +1,44 @@ { "Resources": { - "FunctionOneRole": { - "Type": "AWS::IAM::Role", + "FunctionOne": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "FunctionOneRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, - "FunctionTwoImageBucketPermission": { - "Type": "AWS::Lambda::Permission", + "FunctionOneImageBucketPermission": { "Properties": { "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, "FunctionName": { - "Ref": "FunctionTwo" - }, - "Principal": "s3.amazonaws.com" - } - }, - "Images": { - "Type": "AWS::S3::Bucket", - "Properties": { - "NotificationConfiguration": { - "LambdaConfigurations": [ - { - "Function": { - "Fn::GetAtt": [ - "FunctionTwo", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - }, - { - "Function": { - "Fn::GetAtt": [ - "FunctionOne", - "Arn" - ] - }, - "Event": "s3:ObjectCreated:*" - } - ] + "Ref": "FunctionOne" }, - "PublicAccessBlockConfiguration": { - "BlockPublicAcls": true, - "BlockPublicPolicy": true, - "IgnorePublicAcls": true, - "RestrictPublicBuckets": true + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" } }, - "DependsOn": [ - "FunctionOneImageBucketPermission", - "FunctionTwoImageBucketPermission" - ] + "Type": "AWS::Lambda::Permission" }, - "FunctionTwoRole": { - "Type": "AWS::IAM::Role", + "FunctionOneRole": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -106,25 +51,22 @@ ] } } - ] - } - } - }, - "FunctionOneImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "FunctionOne" + ], + "Version": "2012-10-17" }, - "Principal": "s3.amazonaws.com" - } + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" }, "FunctionTwo": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -140,34 +82,92 @@ "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "FunctionOne": { - "Type": "AWS::Lambda::Function", + "FunctionTwoImageBucketPermission": { "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "FunctionTwo" }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "FunctionOneRole", - "Arn" - ] + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "FunctionTwoRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "Images": { + "DependsOn": [ + "FunctionOneImageBucketPermission", + "FunctionTwoImageBucketPermission" + ], + "Properties": { + "NotificationConfiguration": { + "LambdaConfigurations": [ + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionTwo", + "Arn" + ] + } + }, + { + "Event": "s3:ObjectCreated:*", + "Function": { + "Fn::GetAtt": [ + "FunctionOne", + "Arn" + ] + } + } + ] + }, + "PublicAccessBlockConfiguration": { + "BlockPublicAcls": true, + "BlockPublicPolicy": true, + "IgnorePublicAcls": true, + "RestrictPublicBuckets": true + } + }, + "Type": "AWS::S3::Bucket" } } } diff --git a/tests/translator/output/s3_with_condition.json b/tests/translator/output/s3_with_condition.json index 27d891710c..7b0e41b0b3 100644 --- a/tests/translator/output/s3_with_condition.json +++ b/tests/translator/output/s3_with_condition.json @@ -2,120 +2,120 @@ "Conditions": { "MyCondition": { "Fn::Equals": [ - true, + true, false ] } - }, + }, "Resources": { "Images": { - "Type": "AWS::S3::Bucket", "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { "Fn::If": [ - "MyCondition", + "MyCondition", { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" - }, + } + }, { "Ref": "AWS::NoValue" } ] } ] - }, + }, "Tags": [ { + "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission", "Value": { "Fn::If": [ - "MyCondition", + "MyCondition", { "Ref": "ThumbnailFunctionImageBucketPermission" - }, + }, "no dependency" ] - }, - "Key": "sam:ConditionalDependsOn:ThumbnailFunctionImageBucketPermission" + } } ] - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Condition": "MyCondition", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Condition": "MyCondition", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Condition": "MyCondition", + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - }, - "Condition": "MyCondition" - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - }, - "Condition": "MyCondition" - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.generate_thumbails", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - }, - "Condition": "MyCondition" + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/s3_with_dependsOn.json b/tests/translator/output/s3_with_dependsOn.json index 2dc415eeb9..6b75edaec0 100644 --- a/tests/translator/output/s3_with_dependsOn.json +++ b/tests/translator/output/s3_with_dependsOn.json @@ -1,10 +1,6 @@ { "Resources": { - "Topic": { - "Type": "AWS::SNS::Topic" - }, "Images": { - "Type": "AWS::S3::Bucket", "DependsOn": [ "ThumbnailFunctionImageBucketPermission", "Topic" @@ -13,83 +9,87 @@ "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "Topic": { + "Type": "AWS::SNS::Topic" } } } diff --git a/tests/translator/output/self_managed_kafka_with_intrinsics.json b/tests/translator/output/self_managed_kafka_with_intrinsics.json index 28ab2697a6..87e6dfee7c 100644 --- a/tests/translator/output/self_managed_kafka_with_intrinsics.json +++ b/tests/translator/output/self_managed_kafka_with_intrinsics.json @@ -1,38 +1,28 @@ { "Parameters": { "BatchSizeValue": { - "Type": "Number", - "Default": 100 + "Default": 100, + "Type": "Number" }, - "EnableValue": { - "Type": "String", - "Default": true + "ConsumerGroupValue": { + "Default": "consumergroup1", + "Type": "String" }, - "TopicsValue": { - "Type": "CommaDelimitedList", - "Default": "Topic" + "EnableValue": { + "Default": true, + "Type": "String" }, "KafkaBootstrapServersValue": { - "Type": "CommaDelimitedList", - "Default": "abc.xyz.com:9092,123.45.67.89:9096" + "Default": "abc.xyz.com:9092,123.45.67.89:9096", + "Type": "CommaDelimitedList" }, - "ConsumerGroupValue": { - "Type": "String", - "Default": "consumergroup1" + "TopicsValue": { + "Default": "Topic", + "Type": "CommaDelimitedList" } }, "Resources": { - "KafkaUserSecret": { - "Type": "AWS::SecretsManager::Secret", - "Properties": { - "Name": "KafkaUserPassword", - "SecretString": { - "Fn::Sub": "{\"username\":\"testBrokerUser\",\"password\":\"testBrokerPassword\"}" - } - } - }, "KafkaFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -52,13 +42,57 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" + }, + "KafkaFunctionMyKafkaCluster": { + "Properties": { + "BatchSize": { + "Ref": "BatchSizeValue" + }, + "Enabled": { + "Ref": "EnableValue" + }, + "FunctionName": { + "Ref": "KafkaFunction" + }, + "SelfManagedEventSource": { + "Endpoints": { + "KafkaBootstrapServers": { + "Ref": "KafkaBootstrapServersValue" + } + } + }, + "SelfManagedKafkaEventSourceConfig": { + "ConsumerGroupId": { + "Ref": "ConsumerGroupValue" + } + }, + "SourceAccessConfigurations": [ + { + "Type": "VPC_SUBNET", + "URI": "subnet:subnet-12345" + }, + { + "Type": "VPC_SECURITY_GROUP", + "URI": "security_group:sg-67890" + }, + { + "Type": "BASIC_AUTH", + "URI": { + "Ref": "KafkaUserSecret" + } + } + ], + "Topics": { + "Ref": "TopicsValue" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KafkaFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -71,7 +105,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -113,52 +148,17 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "KafkaFunctionMyKafkaCluster": { - "Type": "AWS::Lambda::EventSourceMapping", + "KafkaUserSecret": { "Properties": { - "BatchSize": { - "Ref": "BatchSizeValue" - }, - "Enabled": { - "Ref": "EnableValue" - }, - "FunctionName": { - "Ref": "KafkaFunction" - }, - "Topics": { - "Ref": "TopicsValue" - }, - "SourceAccessConfigurations": [ - { - "Type": "VPC_SUBNET", - "URI": "subnet:subnet-12345" - }, - { - "Type": "VPC_SECURITY_GROUP", - "URI": "security_group:sg-67890" - }, - { - "Type": "BASIC_AUTH", - "URI": { - "Ref": "KafkaUserSecret" - } - } - ], - "SelfManagedEventSource": { - "Endpoints": { - "KafkaBootstrapServers": { - "Ref": "KafkaBootstrapServersValue" - } - } - }, - "SelfManagedKafkaEventSourceConfig": { - "ConsumerGroupId": { - "Ref": "ConsumerGroupValue" - } + "Name": "KafkaUserPassword", + "SecretString": { + "Fn::Sub": "{\"username\":\"testBrokerUser\",\"password\":\"testBrokerPassword\"}" } - } + }, + "Type": "AWS::SecretsManager::Secret" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/simple_table_ref_parameter_intrinsic.json b/tests/translator/output/simple_table_ref_parameter_intrinsic.json index f2e5119305..07b3755cbe 100644 --- a/tests/translator/output/simple_table_ref_parameter_intrinsic.json +++ b/tests/translator/output/simple_table_ref_parameter_intrinsic.json @@ -1,5 +1,9 @@ { "Parameters": { + "EnableSSE": { + "Default": true, + "Type": "String" + }, "ReadCapacity": { "Default": 15, "Type": "Number" @@ -7,29 +11,11 @@ "WriteCapacity": { "Default": 15, "Type": "Number" - }, - "EnableSSE": { - "Default": true, - "Type": "String" } }, "Resources": { "MinimalTableRefParamLongForm": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "ProvisionedThroughput": { - "WriteCapacityUnits": { - "Ref": "WriteCapacity" - }, - "ReadCapacityUnits": { - "Ref": "ReadCapacity" - } - }, - "SSESpecification": { - "SSEEnabled": { - "Ref": "EnableSSE" - } - }, "AttributeDefinitions": [ { "AttributeName": "id", @@ -38,11 +24,25 @@ ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "ProvisionedThroughput": { + "ReadCapacityUnits": { + "Ref": "ReadCapacity" + }, + "WriteCapacityUnits": { + "Ref": "WriteCapacity" + } + }, + "SSESpecification": { + "SSEEnabled": { + "Ref": "EnableSSE" } - ] - } + } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/simple_table_with_extra_tags.json b/tests/translator/output/simple_table_with_extra_tags.json index a02e088cd8..55ad2e3e58 100644 --- a/tests/translator/output/simple_table_with_extra_tags.json +++ b/tests/translator/output/simple_table_with_extra_tags.json @@ -7,42 +7,42 @@ }, "Resources": { "MinimalTableWithTags": { - "Type": "AWS::DynamoDB::Table", "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } ], "Tags": [ { - "Value": "TagValue1", - "Key": "TagKey1" + "Key": "TagKey1", + "Value": "TagValue1" }, { - "Value": "", - "Key": "TagKey2" + "Key": "TagKey2", + "Value": "" }, { + "Key": "TagKey3", "Value": { "Ref": "TagValueParam" - }, - "Key": "TagKey3" + } }, { - "Value": "123", - "Key": "TagKey4" + "Key": "TagKey4", + "Value": "123" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/simple_table_with_table_name.json b/tests/translator/output/simple_table_with_table_name.json index 57b9ef7a81..3778fe19f3 100644 --- a/tests/translator/output/simple_table_with_table_name.json +++ b/tests/translator/output/simple_table_with_table_name.json @@ -6,66 +6,66 @@ } }, "Resources": { - "MinimalTableWithTableName": { - "Type": "AWS::DynamoDB::Table", + "MinimalTableWithRefTableName": { "Properties": { - "TableName": "MySimpleTable", - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } - }, - "MinimalTableWithRefTableName": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "TableName": { "Ref": "MySimpleTableParameter" - }, - "BillingMode": "PAY_PER_REQUEST", + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTableWithSubTableName": { + "Properties": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } - }, - "MinimalTableWithSubTableName": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "TableName": { "Fn::Sub": "${AWS::StackName}MySimpleTable" - }, - "BillingMode": "PAY_PER_REQUEST", + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTableWithTableName": { + "Properties": { "AttributeDefinitions": [ { "AttributeName": "id", "AttributeType": "S" } ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "id", + "KeyType": "HASH" } - ] - } + ], + "TableName": "MySimpleTable" + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/simpletable.json b/tests/translator/output/simpletable.json index c59f7a660d..7176a71daf 100644 --- a/tests/translator/output/simpletable.json +++ b/tests/translator/output/simpletable.json @@ -1,43 +1,43 @@ { "Resources": { - "MinimalTable": { - "Type": "AWS::DynamoDB::Table", + "CompleteTable": { "Properties": { - "BillingMode": "PAY_PER_REQUEST", "AttributeDefinitions": [ { - "AttributeName": "id", - "AttributeType": "S" + "AttributeName": "member-number", + "AttributeType": "N" } - ], + ], "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "id" + "AttributeName": "member-number", + "KeyType": "HASH" } - ] - } - }, - "CompleteTable": { - "Type": "AWS::DynamoDB::Table", - "Properties": { + ], "ProvisionedThroughput": { - "WriteCapacityUnits": 10, - "ReadCapacityUnits": 20 - }, + "ReadCapacityUnits": 20, + "WriteCapacityUnits": 10 + } + }, + "Type": "AWS::DynamoDB::Table" + }, + "MinimalTable": { + "Properties": { "AttributeDefinitions": [ { - "AttributeName": "member-number", - "AttributeType": "N" + "AttributeName": "id", + "AttributeType": "S" } - ], + ], + "BillingMode": "PAY_PER_REQUEST", "KeySchema": [ { - "KeyType": "HASH", - "AttributeName": "member-number" + "AttributeName": "id", + "KeyType": "HASH" } ] - } + }, + "Type": "AWS::DynamoDB::Table" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/simpletable_with_sse.json b/tests/translator/output/simpletable_with_sse.json index ab4c3d3f59..13df879afc 100644 --- a/tests/translator/output/simpletable_with_sse.json +++ b/tests/translator/output/simpletable_with_sse.json @@ -1,25 +1,25 @@ { - "Resources": { - "TableWithSSE": { - "Type": "AWS::DynamoDB::Table", - "Properties": { - "BillingMode": "PAY_PER_REQUEST", - "SSESpecification": { - "SSEEnabled": true - }, - "AttributeDefinitions": [ - { - "AttributeName": "id", - "AttributeType": "S" - } - ], - "KeySchema": [ - { - "KeyType": "HASH", - "AttributeName": "id" - } - ] + "Resources": { + "TableWithSSE": { + "Properties": { + "AttributeDefinitions": [ + { + "AttributeName": "id", + "AttributeType": "S" + } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "SSESpecification": { + "SSEEnabled": true } - } + }, + "Type": "AWS::DynamoDB::Table" } - } \ No newline at end of file + } +} diff --git a/tests/translator/output/sns.json b/tests/translator/output/sns.json index 8e895e2e81..28d349a75a 100644 --- a/tests/translator/output/sns.json +++ b/tests/translator/output/sns.json @@ -2,87 +2,87 @@ "Resources": { "Notifications": { "Type": "AWS::SNS::Topic" - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "Notifications" - } - } - }, + }, "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", + }, + "Handler": "index.save_notification", "Role": { "Fn::GetAtt": [ - "SaveNotificationFunctionRole", + "SaveNotificationFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "SaveNotificationFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/sns_existing_other_subscription.json b/tests/translator/output/sns_existing_other_subscription.json index 5c28668de5..4016e263f1 100644 --- a/tests/translator/output/sns_existing_other_subscription.json +++ b/tests/translator/output/sns_existing_other_subscription.json @@ -1,96 +1,96 @@ { "Resources": { "Notifications": { - "Type": "AWS::SNS::Topic", "Properties": { "Subscription": [ { - "Endpoint": "my-queue-arn", + "Endpoint": "my-queue-arn", "Protocol": "sqs" } ] - } - }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "Notifications" - } - } - }, + }, + "Type": "AWS::SNS::Topic" + }, "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", + }, + "Handler": "index.save_notification", "Role": { "Fn::GetAtt": [ - "SaveNotificationFunctionRole", + "SaveNotificationFunctionRole", "Arn" ] - }, + }, "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "SaveNotificationFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/sns_existing_sqs.json b/tests/translator/output/sns_existing_sqs.json index a0e9728d8d..b7a5d75181 100644 --- a/tests/translator/output/sns_existing_sqs.json +++ b/tests/translator/output/sns_existing_sqs.json @@ -1,31 +1,11 @@ { "Resources": { - "Queue": { - "Type": "AWS::SQS::Queue" - }, - "Notifications": { - "Type": "AWS::SNS::Topic" - }, "NotificationA": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - { - "Ref": "Queue" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - }, - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -33,15 +13,63 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + } } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "Queue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "Notifications": { + "Type": "AWS::SNS::Topic" + }, + "Queue": { + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" ] - } - } + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "Queue", + "Arn" + ] + }, "FilterPolicy": { "price_usd": [ { @@ -55,23 +83,32 @@ "example_corp" ] }, - "Endpoint": { + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 8, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "Queue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -84,7 +121,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -92,50 +130,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 8, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "Queue", - "Arn" - ] - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/sns_intrinsics.json b/tests/translator/output/sns_intrinsics.json index c591b02664..0622e3631f 100644 --- a/tests/translator/output/sns_intrinsics.json +++ b/tests/translator/output/sns_intrinsics.json @@ -17,46 +17,37 @@ "Notifications": { "Type": "AWS::SNS::Topic" }, - "SaveNotificationFunctionNotificationTopicQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "SaveNotificationFunctionNotificationTopicQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "SaveNotificationFunction": { "Properties": { - "Queues": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Ref": "SaveNotificationFunctionNotificationTopicQueue" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + }, "FilterPolicy": { "Fn::If": [ "MyCondition", @@ -82,26 +73,72 @@ } ] }, + "Protocol": "sqs", "Region": { "Ref": "SnsRegion" }, - "Endpoint": { + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "SaveNotificationFunctionNotificationTopicQueue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SaveNotificationFunctionNotificationTopicQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunctionNotificationTopicQueuePolicy": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } + } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Queues": [ + { + "Ref": "SaveNotificationFunctionNotificationTopicQueue" + } + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -114,7 +151,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -122,50 +160,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/sns_outside_sqs.json b/tests/translator/output/sns_outside_sqs.json index 5761b5cc7d..56287e55fd 100644 --- a/tests/translator/output/sns_outside_sqs.json +++ b/tests/translator/output/sns_outside_sqs.json @@ -1,18 +1,11 @@ { "Resources": { "NotificationB": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue" - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": "sqs:SendMessage", - "Resource": "arn:aws:sqs:us-east-1:123456789012:MyQueue", - "Effect": "Allow", "Condition": { "ArnEquals": { "aws:SourceArn": { @@ -20,18 +13,48 @@ } } }, - "Principal": "*" + "Effect": "Allow", + "Principal": "*", + "Resource": "arn:aws:sqs:us-east-1:123456789012:MyQueue" } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Queues": [ + "https://sqs.us-east-1.amazonaws.com/123456789012/MyQueue" + ] + }, + "Type": "AWS::SQS::QueuePolicy" }, "Notifications": { "Type": "AWS::SNS::Topic" }, + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": "arn:aws:sqs:us-east-1:123456789012:MyQueue", "FilterPolicy": { "price_usd": [ { @@ -45,18 +68,27 @@ "example_corp" ] }, - "Endpoint": "arn:aws:sqs:us-east-1:123456789012:MyQueue", "Protocol": "sqs", "TopicArn": { "Ref": "Notifications" } - } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 8, + "Enabled": true, + "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:MyQueue", + "FunctionName": { + "Ref": "SaveNotificationFunction" + } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -69,7 +101,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", @@ -77,45 +110,12 @@ ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 8, - "Enabled": true, - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "EventSourceArn": "arn:aws:sqs:us-east-1:123456789012:MyQueue" - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/sns_sqs.json b/tests/translator/output/sns_sqs.json index 4ec300e3db..52b69763f8 100644 --- a/tests/translator/output/sns_sqs.json +++ b/tests/translator/output/sns_sqs.json @@ -3,46 +3,37 @@ "Notifications": { "Type": "AWS::SNS::Topic" }, - "SaveNotificationFunctionNotificationTopicQueue": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, - "SaveNotificationFunctionNotificationTopicQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", + "SaveNotificationFunction": { "Properties": { - "Queues": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ { - "Ref": "SaveNotificationFunctionNotificationTopicQueue" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "Effect": "Allow", - "Condition": { - "ArnEquals": { - "aws:SourceArn": { - "Ref": "Notifications" - } - } - }, - "Principal": "*" - } - ] - } - } + ] + }, + "Type": "AWS::Lambda::Function" }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { + "Endpoint": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + }, "FilterPolicy": { "price_usd": [ { @@ -56,33 +47,69 @@ "example_corp" ] }, - "Endpoint": { + "Protocol": "sqs", + "TopicArn": { + "Ref": "Notifications" + } + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicEventSourceMapping": { + "Properties": { + "BatchSize": 10, + "Enabled": true, + "EventSourceArn": { "Fn::GetAtt": [ "SaveNotificationFunctionNotificationTopicQueue", "Arn" ] }, - "Protocol": "sqs", - "TopicArn": { - "Ref": "Notifications" + "FunctionName": { + "Ref": "SaveNotificationFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, - "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", + "SaveNotificationFunctionNotificationTopicQueue": { + "Properties": {}, + "Type": "AWS::SQS::Queue" + }, + "SaveNotificationFunctionNotificationTopicQueuePolicy": { "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ + "PolicyDocument": { + "Statement": [ + { + "Action": "sqs:SendMessage", + "Condition": { + "ArnEquals": { + "aws:SourceArn": { + "Ref": "Notifications" + } + } + }, + "Effect": "Allow", + "Principal": "*", + "Resource": { + "Fn::GetAtt": [ + "SaveNotificationFunctionNotificationTopicQueue", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Queues": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Ref": "SaveNotificationFunctionNotificationTopicQueue" } - ], + ] + }, + "Type": "AWS::SQS::QueuePolicy" + }, + "SaveNotificationFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -95,48 +122,21 @@ ] } } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicEventSourceMapping": { - "Type": "AWS::Lambda::EventSourceMapping", - "Properties": { - "BatchSize": 10, - "Enabled": true, - "EventSourceArn": { - "Fn::GetAtt": [ - "SaveNotificationFunctionNotificationTopicQueue", - "Arn" - ] - }, - "FunctionName": { - "Ref": "SaveNotificationFunction" - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "index.save_notification", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] + ], + "Version": "2012-10-17" }, - "Runtime": "nodejs12.x", + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/sns_topic_outside_template.json b/tests/translator/output/sns_topic_outside_template.json index 560270c866..7bda978b04 100644 --- a/tests/translator/output/sns_topic_outside_template.json +++ b/tests/translator/output/sns_topic_outside_template.json @@ -3,88 +3,88 @@ "SNSTopicArn": { "Type": "String" } - }, + }, "Resources": { + "SaveNotificationFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "notifications.zip" + }, + "Handler": "index.save_notification", + "Role": { + "Fn::GetAtt": [ + "SaveNotificationFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, "SaveNotificationFunctionNotificationTopic": { - "Type": "AWS::SNS::Subscription", "Properties": { "Endpoint": { "Fn::GetAtt": [ - "SaveNotificationFunction", + "SaveNotificationFunction", "Arn" ] - }, - "Protocol": "lambda", + }, + "Protocol": "lambda", "TopicArn": { "Ref": "SNSTopicArn" } - } - }, + }, + "Type": "AWS::SNS::Subscription" + }, + "SaveNotificationFunctionNotificationTopicPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "SaveNotificationFunction" + }, + "Principal": "sns.amazonaws.com", + "SourceArn": { + "Ref": "SNSTopicArn" + } + }, + "Type": "AWS::Lambda::Permission" + }, "SaveNotificationFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "SaveNotificationFunctionNotificationTopicPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "sns.amazonaws.com", - "FunctionName": { - "Ref": "SaveNotificationFunction" - }, - "SourceArn": { - "Ref": "SNSTopicArn" - } - } - }, - "SaveNotificationFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "notifications.zip" - }, - "Handler": "index.save_notification", - "Role": { - "Fn::GetAtt": [ - "SaveNotificationFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/sqs.json b/tests/translator/output/sqs.json index 36bcdb1aa7..caed1e1291 100644 --- a/tests/translator/output/sqs.json +++ b/tests/translator/output/sqs.json @@ -1,36 +1,6 @@ { "Resources": { - "SQSFunctionRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", - "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } - }, "SQSFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -44,14 +14,16 @@ ] }, "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "SQSFunctionMySqsQueue": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 10, "Enabled": false, @@ -59,7 +31,39 @@ "FunctionName": { "Ref": "SQSFunction" } - } + }, + "Type": "AWS::Lambda::EventSourceMapping" + }, + "SQSFunctionRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + "arn:aws:iam::aws:policy/service-role/AWSLambdaSQSQueueExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_api_auth_default_scopes.json b/tests/translator/output/state_machine_with_api_auth_default_scopes.json index 70042db2f2..5b89f7d29a 100644 --- a/tests/translator/output/state_machine_with_api_auth_default_scopes.json +++ b/tests/translator/output/state_machine_with_api_auth_default_scopes.json @@ -1,725 +1,725 @@ { - "Resources": { - "MyApiWithCognitoAuth": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/cognitowithauthnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoWithAuthNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "NONE": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultauthdefaultscopesnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesnone": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesNoneRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitoauthorizerwithdefaultscopes": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoAuthorizerWithDefaultScopesRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [ - "default.delete", - "default.update" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitoauthorizercopesoverwritten": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoAuthorizerScopesOverwrittenRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthWithDefaultScopes": [ - "overwritten.read", - "overwritten.write" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesoverwritten": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesWithOverwrittenRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [ - "overwritten.read", - "overwritten.write" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/cognitodefaultscopesdefaultauthorizer": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyDefaultCognitoAuth": [ - "default.write", - "default.read" - ] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "openapi": "3.0.1", - "components": { - "securitySchemes": { - "MyCognitoAuthWithDefaultScopes": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:2" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyDefaultCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - } - } - } - } + "Resources": { + "MyApiWithCognitoAuth": { + "Properties": { + "Body": { + "components": { + "securitySchemes": { + "MyCognitoAuthWithDefaultScopes": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:2" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyDefaultCognitoAuth": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } } - }, - "MyStateMachineCognitoWithAuthNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoWithAuthNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "openapi": "3.0.1", + "paths": { + "/cognitoauthorizercopesoverwritten": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [ + "overwritten.read", + "overwritten.write" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoAuthorizerScopesOverwrittenRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultScopesNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitoauthorizerwithdefaultscopes": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [ + "default.delete", + "default.update" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoAuthorizerWithDefaultScopesRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitodefaultauthdefaultscopesnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthWithDefaultScopes": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitodefaultscopesdefaultauthorizer": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [ + "default.write", + "default.read" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitodefaultscopesnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyStateMachineCognitoDefaultScopesWithOverwrittenRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesWithOverwrittenRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/cognitodefaultscopesoverwritten": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyDefaultCognitoAuth": [ + "overwritten.read", + "overwritten.write" + ] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoDefaultScopesWithOverwrittenRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/cognitowithauthnone": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "NONE": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineCognitoWithAuthNoneRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "MyApiWithCognitoAuthProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiWithCognitoAuthDeployment57b57dfc88" - }, - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "StageName": "Prod" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiWithCognitoAuthDeployment57b57dfc88": { + "Properties": { + "Description": "RestApi deployment id: 57b57dfc88b1b438a0437eadd869d77e938eedb6", + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiWithCognitoAuthProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiWithCognitoAuthDeployment57b57dfc88" + }, + "RestApiId": { + "Ref": "MyApiWithCognitoAuth" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyStateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyStateMachineCognitoAuthorizerScopesOverwrittenRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiWithCognitoAuthDeployment57b57dfc88": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApiWithCognitoAuth" - }, - "Description": "RestApi deployment id: 57b57dfc88b1b438a0437eadd869d77e938eedb6" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoAuthorizerScopesOverwrittenRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoAuthorizerWithDefaultScopesRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoAuthorizerWithDefaultScopesRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultAuthDefaultScopesNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyStateMachineCognitoAuthorizerWithDefaultScopesRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoAuthorizerWithDefaultScopesRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesDefaultAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineCognitoAuthorizerScopesOverwrittenRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineCognitoAuthorizerScopesOverwrittenRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoDefaultScopesWithOverwrittenRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "MyStateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoDefaultScopesWithOverwrittenRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineCognitoWithAuthNoneRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineCognitoWithAuthNoneRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_api_authorizer.json b/tests/translator/output/state_machine_with_api_authorizer.json index fba1f1847a..0d6927a650 100644 --- a/tests/translator/output/state_machine_with_api_authorizer.json +++ b/tests/translator/output/state_machine_with_api_authorizer.json @@ -1,368 +1,368 @@ { - "Resources": { - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startWithLambdaToken": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaTokenAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + "StateMachineWithLambdaTokenAuthRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaaffc688ce" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startNoAuth": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithNoAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "StateMachineWithLambdaTokenAuthRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + }, + "securityDefinitions": { + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineWithLambdaTokenAuthRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" } - }, - "MyApiDeploymentc2779253ee": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: c2779253eecd9c0b8252440b0cf5ef8d2759b211", - "StageName": "Stage" + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentc2779253ee": { + "Properties": { + "Description": "RestApi deployment id: c2779253eecd9c0b8252440b0cf5ef8d2759b211", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentc2779253ee" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startNoAuth": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithNoAuthorizerRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ] - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentc2779253ee" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } } - }, - "ServerlessRestApiDeploymentaaffc688ce": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aaffc688ce6d1b26ccd7a90641e103263f6240bb", - "StageName": "Stage" + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaaffc688ce": { + "Properties": { + "Description": "RestApi deployment id: aaffc688ce6d1b26ccd7a90641e103263f6240bb", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaaffc688ce" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - }, - "StateMachineWithNoAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaTokenAuthRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startWithLambdaToken": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaTokenAuthRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaTokenAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, - "x-amazon-apigateway-authtype": "custom" - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaTokenAuthRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithNoAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_api_authorizer_maximum.json b/tests/translator/output/state_machine_with_api_authorizer_maximum.json index f4b6bc22fd..bc9136f452 100644 --- a/tests/translator/output/state_machine_with_api_authorizer_maximum.json +++ b/tests/translator/output/state_machine_with_api_authorizer_maximum.json @@ -1,682 +1,682 @@ { - "Resources": { - "MyApiDeploymentde088eafc3": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: de088eafc3dd099f3b79506a6e0542dadb9fcd23", - "StageName": "Stage" - } - }, - "MyApiMyLambdaRequestAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "NONE": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithNoAuthorizerRole", + "Arn" ] - } - } - }, - "StateMachineWithLambdaRequestAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithLambdaRequestAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + } + }, + "/users": { + "delete": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaRequestAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + "StateMachineWithLambdaRequestAuthorizerRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "StateMachineWithDefaultAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithDefaultAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + }, + "patch": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyLambdaTokenAuthNoneFunctionInvokeRole": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithLambdaTokenAuthorizerRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithNoAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "NONE": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/users": { - "put": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithDefaultAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyCognitoAuthMultipleUserPools": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "patch": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaTokenAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaTokenAuthNoneFunctionInvokeRole": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - "delete": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineWithLambdaRequestAuthorizerRole", - "Arn" - ] - }, - "type": "aws" - }, - "security": [ - { - "MyLambdaRequestAuth": [] - }, - { - "api_key": [] - } - ], - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "securityDefinitions": { - "MyLambdaTokenAuthNoneFunctionInvokeRole": { - "in": "header", - "type": "apiKey", - "name": "Authorization", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 0, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - } - }, - "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuthMultipleUserPools": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader2", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression2", - "providerARNs": [ - "arn:aws:2", - "arn:aws:3" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaRequestAuth": { - "in": "header", - "type": "apiKey", - "name": "Unused", - "x-amazon-apigateway-authorizer": { - "type": "request", - "authorizerResultTtlInSeconds": 0, - "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access" - }, - "x-amazon-apigateway-authtype": "custom" - }, - "MyCognitoAuth": { - "in": "header", - "type": "apiKey", - "name": "MyAuthorizationHeader", - "x-amazon-apigateway-authorizer": { - "identityValidationExpression": "myauthvalidationexpression", - "providerARNs": [ - "arn:aws:1" - ], - "type": "cognito_user_pools" - }, - "x-amazon-apigateway-authtype": "cognito_user_pools" - }, - "MyLambdaTokenAuth": { - "in": "header", - "type": "apiKey", - "name": "MyCustomAuthHeader", - "x-amazon-apigateway-authorizer": { - "type": "token", - "authorizerResultTtlInSeconds": 20, - "authorizerUri": { - "Fn::Sub": [ - "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", - { - "__FunctionArn__": "arn:aws" - } - ] - }, - "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", - "identityValidationExpression": "mycustomauthexpression" - }, - "x-amazon-apigateway-authtype": "custom" - }, - "api_key": { - "type": "apiKey", - "name": "x-api-key", - "in": "header" - } + }, + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuthMultipleUserPools": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "MyApiMyLambdaTokenAuthAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } + }, + "put": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "security": [ + { + "MyCognitoAuth": [] + }, + { + "api_key": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineWithDefaultAuthorizerRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + }, + "securityDefinitions": { + "MyCognitoAuth": { + "in": "header", + "name": "MyAuthorizationHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression", + "providerARNs": [ + "arn:aws:1" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyCognitoAuthMultipleUserPools": { + "in": "header", + "name": "MyAuthorizationHeader2", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "identityValidationExpression": "myauthvalidationexpression2", + "providerARNs": [ + "arn:aws:2", + "arn:aws:3" + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + }, + "MyLambdaRequestAuth": { + "in": "header", + "name": "Unused", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "Tags": [ + ] + }, + "identitySource": "method.request.header.Authorization1, method.request.querystring.Authorization2, stageVariables.Authorization3, context.Authorization4", + "type": "request" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "MyLambdaTokenAuth": { + "in": "header", + "name": "MyCustomAuthHeader", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerCredentials": "arn:aws:iam::123456789012:role/S3Access", + "authorizerResultTtlInSeconds": 20, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "__FunctionArn__": "arn:aws" } - ] - } - }, - "StateMachineWithLambdaTokenAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ + ] + }, + "identityValidationExpression": "mycustomauthexpression", + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "MyLambdaTokenAuthNoneFunctionInvokeRole": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "authorizerResultTtlInSeconds": 0, + "authorizerUri": { + "Fn::Sub": [ + "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${__FunctionArn__}/invocations", { - "PolicyName": "StateMachineWithLambdaTokenAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "__FunctionArn__": "arn:aws" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ] + }, + "type": "token" + }, + "x-amazon-apigateway-authtype": "custom" + }, + "api_key": { + "in": "header", + "name": "x-api-key", + "type": "apiKey" + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeploymentde088eafc3": { + "Properties": { + "Description": "RestApi deployment id: de088eafc3dd099f3b79506a6e0542dadb9fcd23", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiMyLambdaRequestAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": "arn:aws", + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", + { + "__ApiId__": { + "Ref": "MyApi" + } + } + ] + } + }, + "Type": "AWS::Lambda::Permission" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeploymentde088eafc3" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiMyLambdaTokenAuthNoneFunctionInvokeRoleAuthorizerPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "Principal": "apigateway.amazonaws.com", - "FunctionName": "arn:aws", - "SourceArn": { - "Fn::Sub": [ - "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/authorizers/*", - { - "__ApiId__": { - "Ref": "MyApi" - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithCognitoMultipleUserPoolsAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithDefaultAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeploymentde088eafc3" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithDefaultAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaRequestAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "StateMachineWithCognitoMultipleUserPoolsAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithCognitoMultipleUserPoolsAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaRequestAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithLambdaTokenAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "StateMachineWithNoAuthorizerRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineWithLambdaTokenAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineWithNoAuthorizerRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineWithNoAuthorizerRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_api_resource_policy.json b/tests/translator/output/state_machine_with_api_resource_policy.json index 262ecdf372..7f201b4831 100644 --- a/tests/translator/output/state_machine_with_api_resource_policy.json +++ b/tests/translator/output/state_machine_with_api_resource_policy.json @@ -1,474 +1,474 @@ { - "Resources": { - "MyStateMachineGetHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachineGetHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + "Resources": { + "ExplicitApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/one": { + "get": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachineGetHtmlRole", + "Arn" ] - } - } - }, - "ExplicitApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/one": { - "get": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachineGetHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/three": { - "put": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachinePutHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - }, - "/two": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "MyStateMachinePostHtmlRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Allow", - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "NotIpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/GET/one", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Allow", - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "NotIpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - }, - { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/two", - { - "__Stage__": null - } - ] - } - ], - "Effect": "Deny", - "Condition": { - "IpAddress": { - "aws:SourceIp": [ - "1.2.3.4" - ] - } - }, - "Principal": "*" - } - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } - } - }, - "ExplicitApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ExplicitApiDeployment17065a95ba" - }, - "RestApiId": { - "Ref": "ExplicitApi" - }, - "StageName": "Prod" - } - }, - "MyStateMachinePutHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachinePutHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } + } + }, + "/three": { + "put": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachinePutHtmlRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + }, + "/two": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "MyStateMachinePostHtmlRole", + "Arn" ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${MyStateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } } + } } - }, - "MyStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "MyStateMachineRole", - "Arn" + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": [ + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } ] - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "IpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/GET/one", + { + "__Stage__": null + } + ] + } ] + }, + { + "Action": "execute-api:Invoke", + "Effect": "Allow", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "NotIpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + }, + { + "Action": "execute-api:Invoke", + "Condition": { + "IpAddress": { + "aws:SourceIp": [ + "1.2.3.4" + ] + } + }, + "Effect": "Deny", + "Principal": "*", + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/two", + { + "__Stage__": null + } + ] + } + ] + } + ], + "Version": "2012-10-17" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ExplicitApiDeployment17065a95ba": { + "Properties": { + "Description": "RestApi deployment id: 17065a95bac1ac0e3dc22fef2ff7aa228539b1d2", + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ExplicitApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ExplicitApiDeployment17065a95ba" + }, + "RestApiId": { + "Ref": "ExplicitApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "MyStateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "MyStateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "MyStateMachineGetHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "ExplicitApiDeployment17065a95ba": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ExplicitApi" - }, - "Description": "RestApi deployment id: 17065a95bac1ac0e3dc22fef2ff7aa228539b1d2", - "StageName": "Stage" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachineGetHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachinePostHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "MyStateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "MyStateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } + } + ] + }, + "PolicyName": "MyStateMachinePostHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachinePutHtmlRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyStateMachinePostHtmlRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "MyStateMachinePostHtmlRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "MyStateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "MyStateMachine" + } } + ] + }, + "PolicyName": "MyStateMachinePutHtmlRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MyStateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "MyStateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_condition.json b/tests/translator/output/state_machine_with_condition.json index 7d67abe1a4..f723ffa179 100644 --- a/tests/translator/output/state_machine_with_condition.json +++ b/tests/translator/output/state_machine_with_condition.json @@ -2,30 +2,30 @@ "Conditions": { "TestCondition": { "Fn::Equals": [ - "test", + "test", "test" ] } - }, + }, "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", + "Condition": "TestCondition", "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachine", "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachine", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - }, - "Condition": "TestCondition" + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_condition_and_events.json b/tests/translator/output/state_machine_with_condition_and_events.json index 413d4ac37b..fea4208988 100644 --- a/tests/translator/output/state_machine_with_condition_and_events.json +++ b/tests/translator/output/state_machine_with_condition_and_events.json @@ -1,297 +1,297 @@ { - "Conditions": { - "TestCondition": { - "Fn::Equals": [ - "test", - "test" - ] - } - }, - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } + "Conditions": { + "TestCondition": { + "Fn::Equals": [ + "test", + "test" + ] + } + }, + "Resources": { + "ServerlessRestApi": { + "Condition": "TestCondition", + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "Fn::If": [ + "TestCondition", + { + "post": { + "Fn::If": [ + "TestCondition", + { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } + }, + "type": "aws", + "uri": { + "Fn::If": [ + "TestCondition", + { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + }, + { + "Ref": "AWS::NoValue" + } + ] + } } + }, + { + "Ref": "AWS::NoValue" + } ] + } + }, + { + "Ref": "AWS::NoValue" } - }, - "Condition": "TestCondition" - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachine", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + ] + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeploymentaeae651245": { + "Condition": "TestCondition", + "Properties": { + "Description": "RestApi deployment id: aeae651245fe7d417a17f2bea50b255f2727e2b8", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Condition": "TestCondition", + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeploymentaeae651245" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Condition": "TestCondition", + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineCWEvent": { + "Condition": "TestCondition", + "Properties": { + "EventPattern": { + "detail": { + "state": [ + "terminated" + ] + } + }, + "Targets": [ + { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] + } + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineCWEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" ] - }, - "Condition": "TestCondition" - }, - "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeploymentaeae651245" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - }, - "Condition": "TestCondition" - }, - "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } - ], - "Name": "TestSchedule" - }, - "Condition": "TestCondition" - }, - "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "EventPattern": { - "detail": { - "state": [ - "terminated" - ] - } - }, - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineMyApiEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] - }, - "Condition": "TestCondition" - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "Fn::If": [ - "TestCondition", - { - "post": { - "Fn::If": [ - "TestCondition", - { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::If": [ - "TestCondition", - { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - { - "Ref": "AWS::NoValue" - } - ] - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - { - "Ref": "AWS::NoValue" - } - ] - } - }, - "swagger": "2.0" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - }, - "ServerlessRestApiDeploymentaeae651245": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: aeae651245fe7d417a17f2bea50b255f2727e2b8", - "StageName": "Stage" - }, - "Condition": "TestCondition" - }, - "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineScheduleEvent": { + "Condition": "TestCondition", + "Properties": { + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ + { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" + ] + } + } + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineScheduleEventRole": { + "Condition": "TestCondition", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "events.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } - }, - "Condition": "TestCondition" - } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_cwe.json b/tests/translator/output/state_machine_with_cwe.json index 95940a3534..fb1f076239 100644 --- a/tests/translator/output/state_machine_with_cwe.json +++ b/tests/translator/output/state_machine_with_cwe.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,76 +24,61 @@ "terminated" ] } - }, + }, "State": "ENABLED", "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_definition_S3_object.json b/tests/translator/output/state_machine_with_definition_S3_object.json index e01d31fd66..4bac03fbf8 100644 --- a/tests/translator/output/state_machine_with_definition_S3_object.json +++ b/tests/translator/output/state_machine_with_definition_S3_object.json @@ -1,138 +1,138 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "states.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithDefinitionInS3", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithDefinitionInS3", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_definition_S3_string.json b/tests/translator/output/state_machine_with_definition_S3_string.json index 97f3b26e50..c4de655b58 100644 --- a/tests/translator/output/state_machine_with_definition_S3_string.json +++ b/tests/translator/output/state_machine_with_definition_S3_string.json @@ -1,137 +1,137 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "states.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithDefinitionInS3", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithDefinitionInS3", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "Key": "stateMachine:createdBy", + "Value": "SAM" } - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_definition_substitutions.json b/tests/translator/output/state_machine_with_definition_substitutions.json index 5bae321efb..2e75645929 100644 --- a/tests/translator/output/state_machine_with_definition_substitutions.json +++ b/tests/translator/output/state_machine_with_definition_substitutions.json @@ -1,13 +1,12 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ "MyFunctionRole", @@ -17,65 +16,16 @@ "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -88,38 +38,23 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "my_state_var_1": "Pass", - "my_state_var_2": "Task" - }, - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, "DefinitionString": { "Fn::Join": [ "\n", @@ -143,13 +78,78 @@ ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + }, + "my_state_var_1": "Pass", + "my_state_var_2": "Task" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_eb_dlq.json b/tests/translator/output/state_machine_with_eb_dlq.json index e49e64256f..24a206c3d4 100644 --- a/tests/translator/output/state_machine_with_eb_dlq.json +++ b/tests/translator/output/state_machine_with_eb_dlq.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,78 +24,63 @@ "terminated" ] } - }, + }, "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "DeadLetterConfig": { + "Arn": "TestDlqArn" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "DeadLetterConfig": { - "Arn": "TestDlqArn" - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_eb_dlq_generated.json b/tests/translator/output/state_machine_with_eb_dlq_generated.json index 7e57f89263..70f2a5724d 100644 --- a/tests/translator/output/state_machine_with_eb_dlq_generated.json +++ b/tests/translator/output/state_machine_with_eb_dlq_generated.json @@ -1,11 +1,22 @@ { "Resources": { - "TestDLQ": { - "Type": "AWS::SQS::Queue", - "Properties": {} - }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -13,121 +24,110 @@ "terminated" ] } - }, + }, "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, + "Arn": { + "Ref": "StateMachine" + }, "DeadLetterConfig": { "Arn": { "Fn::GetAtt": [ - "TestDLQ", + "TestDLQ", "Arn" ] } - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventQueuePolicy": { - "Type": "AWS::SQS::QueuePolicy", "Properties": { - "Queues": [ - { - "Ref": "TestDLQ" - } - ], "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "sqs:SendMessage", - "Resource": { - "Fn::GetAtt": [ - "TestDLQ", - "Arn" - ] - }, - "Effect": "Allow", + "Action": "sqs:SendMessage", "Condition": { "ArnEquals": { "aws:SourceArn": { "Fn::GetAtt": [ - "StateMachineCWEvent", + "StateMachineCWEvent", "Arn" ] } } - }, + }, + "Effect": "Allow", "Principal": { "Service": "events.amazonaws.com" + }, + "Resource": { + "Fn::GetAtt": [ + "TestDLQ", + "Arn" + ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Queues": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Ref": "TestDLQ" } ] - } - }, + }, + "Type": "AWS::SQS::QueuePolicy" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "TestDLQ": { + "Properties": {}, + "Type": "AWS::SQS::Queue" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_eb_retry_policy.json b/tests/translator/output/state_machine_with_eb_retry_policy.json index bff94e177a..18813d71f7 100644 --- a/tests/translator/output/state_machine_with_eb_retry_policy.json +++ b/tests/translator/output/state_machine_with_eb_retry_policy.json @@ -1,7 +1,22 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -9,79 +24,64 @@ "terminated" ] } - }, + }, "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineCWEventRole", - "Arn" - ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", "Arn": { "Ref": "StateMachine" - }, + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 300, + "MaximumEventAgeInSeconds": 300, "MaximumRetryAttempts": 5 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineCWEventRole", + "Arn" + ] } } ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_event_schedule_state.json b/tests/translator/output/state_machine_with_event_schedule_state.json index a38e480ed1..c3b472071f 100644 --- a/tests/translator/output/state_machine_with_event_schedule_state.json +++ b/tests/translator/output/state_machine_with_event_schedule_state.json @@ -1,7 +1,6 @@ { "Resources": { "ScheduledStateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -14,10 +13,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "ScheduledStateMachineSchedule1": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -37,13 +36,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule1Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -56,11 +54,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule1RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -71,13 +69,14 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule1RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ScheduledStateMachineSchedule2": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -99,13 +98,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule2Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -118,11 +116,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule2RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -133,13 +131,14 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule2RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" }, "ScheduledStateMachineSchedule3": { - "Type": "AWS::Events::Rule", "Properties": { "Description": "Test Schedule", "Name": "test-schedule", @@ -161,13 +160,12 @@ } } ] - } + }, + "Type": "AWS::Events::Rule" }, "ScheduledStateMachineSchedule3Role": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -180,11 +178,11 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "Policies": [ { - "PolicyName": "ScheduledStateMachineSchedule3RoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { @@ -195,10 +193,12 @@ } } ] - } + }, + "PolicyName": "ScheduledStateMachineSchedule3RoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/state_machine_with_explicit_api.json b/tests/translator/output/state_machine_with_explicit_api.json index 59f36f236d..56e6c2b52e 100644 --- a/tests/translator/output/state_machine_with_explicit_api.json +++ b/tests/translator/output/state_machine_with_explicit_api.json @@ -1,202 +1,202 @@ { - "Resources": { - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } + "Resources": { + "MyApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ] + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "MyApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "MyApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "MyApiDeployment05bc9f394c" + }, + "RestApiId": { + "Ref": "MyApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "MyApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "MyApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, - "MyApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "MyApiDeployment05bc9f394c" - }, - "RestApiId": { - "Ref": "MyApi" - }, - "StageName": "Prod" - } - }, - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - }, - "MyApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - } - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_express_logging.json b/tests/translator/output/state_machine_with_express_logging.json index ede760c3a2..e6ac7e19b8 100644 --- a/tests/translator/output/state_machine_with_express_logging.json +++ b/tests/translator/output/state_machine_with_express_logging.json @@ -1,180 +1,180 @@ { "Resources": { + "ExpressLogGroup": { + "Type": "AWS::Logs::LogGroup" + }, "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "DefinitionSubstitutions": { + "my_lambda_arn": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + }, + "LoggingConfiguration": { + "Destinations": [ + { + "CloudWatchLogsLogGroup": { + "LogGroupArn": { + "Fn::GetAtt": [ + "ExpressLogGroup", + "Arn" + ] + } + } + } + ], + "IncludeExecutionData": false, + "Level": "FATAL" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStandardStateMachineWithLogging", + "StateMachineType": "EXPRESS", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "lambda:InvokeFunction", + "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] - }, - "Effect": "Allow" + } } - ] - } - }, + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + }, { - "PolicyName": "StateMachineRolePolicy1", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", "logs:DescribeLogGroups" - ], + ], + "Effect": "Allow", "Resource": [ "*" - ], - "Effect": "Allow" + ] } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy1" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "ExpressLogGroup": { - "Type": "AWS::Logs::LogGroup" - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStandardStateMachineWithLogging", - "DefinitionSubstitutions": { - "my_lambda_arn": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - } - }, - "LoggingConfiguration": { - "IncludeExecutionData": false, - "Level": "FATAL", - "Destinations": [ - { - "CloudWatchLogsLogGroup": { - "LogGroupArn": { - "Fn::GetAtt": [ - "ExpressLogGroup", - "Arn" - ] - } - } - } - ] - }, - "StateMachineType": "EXPRESS", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_implicit_api.json b/tests/translator/output/state_machine_with_implicit_api.json index 0a76883a3b..b291010cd9 100644 --- a/tests/translator/output/state_machine_with_implicit_api.json +++ b/tests/translator/output/state_machine_with_implicit_api.json @@ -1,202 +1,202 @@ { - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + "StateMachineMyApiEventRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment05bc9f394c" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment05bc9f394c" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0" + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_implicit_api_globals.json b/tests/translator/output/state_machine_with_implicit_api_globals.json index b8fb271d47..f77158e539 100644 --- a/tests/translator/output/state_machine_with_implicit_api_globals.json +++ b/tests/translator/output/state_machine_with_implicit_api_globals.json @@ -1,224 +1,224 @@ { - "Resources": { - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "apigateway.amazonaws.com" - ] - } - } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { + "Resources": { + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] + "StateMachineMyApiEventRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" } - ] - } - }, - "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", - "Properties": { - "DeploymentId": { - "Ref": "ServerlessRestApiDeployment1f01b589d4" - }, - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment1f01b589d4": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 1f01b589d4e226c84a3e14ca738b5d060e7b611a", - "StageName": "Stage" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "*", - "Resource": "*", - "Effect": "Deny" - } - ] - } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" } - ], - "Tags": [ + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-policy": { + "Statement": { + "Action": "execute-api:Invoke", + "Effect": "Deny", + "Principal": { + "AWS": [ + "12345" + ] + }, + "Resource": [ + { + "Fn::Sub": [ + "execute-api:/${__Stage__}/POST/startMyExecution", { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "__Stage__": "Prod" } + ] + } + ] + }, + "Version": "2012-10-17" + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment1f01b589d4": { + "Properties": { + "Description": "RestApi deployment id: 1f01b589d4e226c84a3e14ca738b5d060e7b611a", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ServerlessRestApiProdStage": { + "Properties": { + "DeploymentId": { + "Ref": "ServerlessRestApiDeployment1f01b589d4" + }, + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Prod" + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineMyApiEventRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" ] + } } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" - } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" - } - } - } - } - }, - "swagger": "2.0", - "x-amazon-apigateway-policy": { - "Version": "2012-10-17", - "Statement": { - "Action": "execute-api:Invoke", - "Resource": [ - { - "Fn::Sub": [ - "execute-api:/${__Stage__}/POST/startMyExecution", - { - "__Stage__": "Prod" - } - ] - } - ], - "Effect": "Deny", - "Principal": { - "AWS": [ - "12345" - ] - } - } - } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } } + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } } - } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "*", + "Effect": "Deny", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/state_machine_with_inline_definition.json b/tests/translator/output/state_machine_with_inline_definition.json index 722bc9ec70..5564d443ee 100644 --- a/tests/translator/output/state_machine_with_inline_definition.json +++ b/tests/translator/output/state_machine_with_inline_definition.json @@ -1,89 +1,89 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyBasicStateMachine", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Deny" + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyBasicStateMachine", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_inline_definition_intrinsics.json b/tests/translator/output/state_machine_with_inline_definition_intrinsics.json index 7c7f91219d..b1ec1b9b92 100644 --- a/tests/translator/output/state_machine_with_inline_definition_intrinsics.json +++ b/tests/translator/output/state_machine_with_inline_definition_intrinsics.json @@ -1,82 +1,32 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "MyFunctionRole", "Arn" ] }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,21 +39,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ @@ -128,12 +79,14 @@ ] ] }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, "RoleArn": { "Fn::GetAtt": [ "StateMachineRole", @@ -141,16 +94,63 @@ ] }, "StateMachineName": "MyBasicStateMachine", - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StateMachineType": "STANDARD" - } + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_inline_policies.json b/tests/translator/output/state_machine_with_inline_policies.json index 7c7f91219d..b1ec1b9b92 100644 --- a/tests/translator/output/state_machine_with_inline_policies.json +++ b/tests/translator/output/state_machine_with_inline_policies.json @@ -1,82 +1,32 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ "MyFunctionRole", "Arn" ] }, - "Runtime": "python2.7" - } - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - } - ], + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -89,21 +39,22 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionString": { "Fn::Join": [ @@ -128,12 +79,14 @@ ] ] }, - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] } - ], + }, "RoleArn": { "Fn::GetAtt": [ "StateMachineRole", @@ -141,16 +94,63 @@ ] }, "StateMachineName": "MyBasicStateMachine", - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" }, - "StateMachineType": "STANDARD" - } + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_managed_policy.json b/tests/translator/output/state_machine_with_managed_policy.json index 82124708d1..2e76d51baa 100644 --- a/tests/translator/output/state_machine_with_managed_policy.json +++ b/tests/translator/output/state_machine_with_managed_policy.json @@ -1,57 +1,57 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithManagedPolicy", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/AmazonDynamoDBFullAccess" - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithManagedPolicy", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_null_events.json b/tests/translator/output/state_machine_with_null_events.json index eb62a90415..772ee4032d 100644 --- a/tests/translator/output/state_machine_with_null_events.json +++ b/tests/translator/output/state_machine_with_null_events.json @@ -1,7 +1,6 @@ { "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -14,7 +13,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_permissions_boundary.json b/tests/translator/output/state_machine_with_permissions_boundary.json index b3823b73bd..e35ce7194c 100644 --- a/tests/translator/output/state_machine_with_permissions_boundary.json +++ b/tests/translator/output/state_machine_with_permissions_boundary.json @@ -1,114 +1,159 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ], - "ReservedConcurrentExecutions": 100, - "Handler": "hello.handler", + }, + "Handler": "hello.handler", + "ReservedConcurrentExecutions": 100, "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7" - } - }, - "StateMachineMyApiEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Policies": [ + }, + "Runtime": "python2.7", + "Tags": [ { - "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "MyFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "apigateway.amazonaws.com" + "lambda.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachine", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - }, + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "ServerlessRestApi": { + "Properties": { + "Body": { + "info": { + "title": { + "Ref": "AWS::StackName" + }, + "version": "1.0" + }, + "paths": { + "/startMyExecution": { + "post": { + "responses": { + "200": { + "description": "OK" + }, + "400": { + "description": "Bad Request" + } + }, + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::GetAtt": [ + "StateMachineMyApiEventRole", + "Arn" + ] + }, + "httpMethod": "POST", + "requestTemplates": { + "application/json": { + "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" + } + }, + "responses": { + "200": { + "statusCode": "200" + }, + "400": { + "statusCode": "400" + } + }, + "type": "aws", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" + } + } + } + } + }, + "swagger": "2.0" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ServerlessRestApiDeployment05bc9f394c": { + "Properties": { + "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", + "RestApiId": { + "Ref": "ServerlessRestApi" + }, + "StageName": "Stage" + }, + "Type": "AWS::ApiGateway::Deployment" + }, "ServerlessRestApiProdStage": { - "Type": "AWS::ApiGateway::Stage", "Properties": { "DeploymentId": { "Ref": "ServerlessRestApiDeployment05bc9f394c" - }, + }, "RestApiId": { "Ref": "ServerlessRestApi" - }, + }, "StageName": "Prod" - } - }, - "ServerlessRestApiDeployment05bc9f394c": { - "Type": "AWS::ApiGateway::Deployment", + }, + "Type": "AWS::ApiGateway::Stage" + }, + "StateMachine": { "Properties": { - "RestApiId": { - "Ref": "ServerlessRestApi" - }, - "Description": "RestApi deployment id: 05bc9f394c3ca5d24b8d6dc69d133762afd1298e", - "StageName": "Stage" - } - }, + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachine", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineCWEvent": { - "Type": "AWS::Events::Rule", "Properties": { "EventPattern": { "detail": { @@ -116,257 +161,212 @@ "terminated" ] } - }, + }, "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineCWEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineCWEventRole", + "StateMachineCWEventRole", "Arn" ] - }, - "Id": "StateMachineCWEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, - "MyFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineCWEventRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ - "lambda.amazonaws.com" + "events.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], - "Tags": [ + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Policies": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy" } ] - } - }, - "ServerlessRestApi": { - "Type": "AWS::ApiGateway::RestApi", + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineMyApiEventRole": { "Properties": { - "Body": { - "info": { - "version": "1.0", - "title": { - "Ref": "AWS::StackName" + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "apigateway.amazonaws.com" + ] + } } - }, - "paths": { - "/startMyExecution": { - "post": { - "x-amazon-apigateway-integration": { - "responses": { - "200": { - "statusCode": "200" - }, - "400": { - "statusCode": "400" - } - }, - "uri": { - "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:states:action/StartExecution" - }, - "httpMethod": "POST", - "requestTemplates": { - "application/json": { - "Fn::Sub": "{\"input\": \"$util.escapeJavaScript($input.json('$'))\", \"stateMachineArn\": \"${StateMachine}\"}" - } - }, - "credentials": { - "Fn::GetAtt": [ - "StateMachineMyApiEventRole", - "Arn" - ] - }, - "type": "aws" - }, - "responses": { - "200": { - "description": "OK" - }, - "400": { - "description": "Bad Request" + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" } } - } - } - }, - "swagger": "2.0" - } - } - }, + ] + }, + "PolicyName": "StateMachineMyApiEventRoleStartExecutionPolicy" + } + ] + }, + "Type": "AWS::IAM::Role" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" - ], + ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ - "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", + "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", { "functionName": { "Ref": "MyFunction" } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "StateMachineRolePolicy0" } - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } - }, - "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::IAM::Role" + }, + "StateMachineScheduleEvent": { "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", - "Policies": [ + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "Targets": [ { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" ] } } - ], + ] + }, + "Type": "AWS::Events::Rule" + }, + "StateMachineScheduleEventRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", - "Properties": { - "ScheduleExpression": "rate(1 minute)", - "Targets": [ - { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" - } - } - ], - "Name": "TestSchedule" - } - }, - "StateMachineCWEventRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", + ], + "Version": "2012-10-17" + }, + "PermissionsBoundary": "arn:aws:1234:iam:boundary/CustomerCreatedPermissionsBoundary", "Policies": [ { - "PolicyName": "StateMachineCWEventRoleStartExecutionPolicy", "PolicyDocument": { "Statement": [ { - "Action": "states:StartExecution", + "Action": "states:StartExecution", + "Effect": "Allow", "Resource": { "Ref": "StateMachine" - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "events.amazonaws.com" - ] - } - } - ] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_role.json b/tests/translator/output/state_machine_with_role.json index 0db8c03ab0..7b3b87fb4b 100644 --- a/tests/translator/output/state_machine_with_role.json +++ b/tests/translator/output/state_machine_with_role.json @@ -1,22 +1,22 @@ { "Resources": { "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachineWithRole", "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", + "Bucket": "sam-demo-bucket", "Key": "my-state-machine.asl.json" - }, - "StateMachineType": "STANDARD", + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithRole", + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_sam_policy_templates.json b/tests/translator/output/state_machine_with_sam_policy_templates.json index c14e8cd07e..848257ccdc 100644 --- a/tests/translator/output/state_machine_with_sam_policy_templates.json +++ b/tests/translator/output/state_machine_with_sam_policy_templates.json @@ -1,40 +1,7 @@ { "Resources": { - "ResolverLambda": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Handler": "resolver.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "resolver.zip" - }, - "Role": { - "Fn::GetAtt": [ - "ResolverLambdaRole", - "Arn" - ] - }, - "Runtime": "python3.8", - "Tags": [ - { - "Value": "SAM", - "Key": "lambda:createdBy" - } - ] - } - }, "NestedWorkflow": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_1": { - "Fn::GetAtt": [ - "StarterLambda", - "Arn" - ] - } - }, - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", "DefinitionString": { "Fn::Join": [ "\n", @@ -60,67 +27,49 @@ ] ] }, + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "StarterLambda", + "Arn" + ] + } + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, - "StarterLambda": { - "Type": "AWS::Lambda::Function", + "OutputStore": { "Properties": { - "Handler": "starter.handler", - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "starter.zip" - }, - "Role": { - "Fn::GetAtt": [ - "StarterLambdaRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ + "AttributeDefinitions": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "AttributeName": "id", + "AttributeType": "S" } - ] - } + ], + "BillingMode": "PAY_PER_REQUEST", + "KeySchema": [ + { + "AttributeName": "id", + "KeyType": "HASH" + } + ], + "TableName": "MySimpleTable" + }, + "Type": "AWS::DynamoDB::Table" + }, + "ProcessingQueue": { + "Type": "AWS::SQS::Queue" }, "ProcessingWorkflow": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "DefinitionSubstitutions": { - "definition_substitution_4": { - "Ref": "NestedWorkflow" - }, - "definition_substitution_5": { - "Ref": "OutputStore" - }, - "definition_substitution_2": { - "Ref": "ResolverLambda" - }, - "definition_substitution_3": { - "Ref": "ProcessingQueue" - }, - "definition_substitution_1": { - "Fn::GetAtt": [ - "StarterLambda", - "Arn" - ] - } - }, - "RoleArn": { - "Fn::GetAtt": [ - "ProcessingWorkflowRole", - "Arn" - ] - }, "DefinitionString": { "Fn::Join": [ "\n", @@ -231,50 +180,45 @@ ] ] }, - "StateMachineType": "STANDARD", - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "DefinitionSubstitutions": { + "definition_substitution_1": { + "Fn::GetAtt": [ + "StarterLambda", + "Arn" + ] + }, + "definition_substitution_2": { + "Ref": "ResolverLambda" + }, + "definition_substitution_3": { + "Ref": "ProcessingQueue" + }, + "definition_substitution_4": { + "Ref": "NestedWorkflow" + }, + "definition_substitution_5": { + "Ref": "OutputStore" } - ] - } - }, - "StarterLambdaRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - } + }, + "RoleArn": { + "Fn::GetAtt": [ + "ProcessingWorkflowRole", + "Arn" ] }, - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "StateMachineType": "STANDARD", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "ProcessingWorkflowRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -287,18 +231,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "ProcessingWorkflowRolePolicy0", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -308,20 +253,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy0" }, { - "PolicyName": "ProcessingWorkflowRolePolicy1", "PolicyDocument": { "Statement": [ { "Action": [ "sqs:SendMessage*" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:sqs:${AWS::Region}:${AWS::AccountId}:${queueName}", @@ -334,20 +279,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy1" }, { - "PolicyName": "ProcessingWorkflowRolePolicy2", "PolicyDocument": { "Statement": [ { "Action": [ "lambda:InvokeFunction" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:lambda:${AWS::Region}:${AWS::AccountId}:function:${functionName}*", @@ -357,20 +302,20 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy2" }, { - "PolicyName": "ProcessingWorkflowRolePolicy3", "PolicyDocument": { "Statement": [ { "Action": [ "states:StartExecution" ], + "Effect": "Allow", "Resource": { "Fn::Sub": [ "arn:${AWS::Partition}:states:${AWS::Region}:${AWS::AccountId}:stateMachine:${stateMachineName}", @@ -383,14 +328,13 @@ } } ] - }, - "Effect": "Allow" + } } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy3" }, { - "PolicyName": "ProcessingWorkflowRolePolicy4", "PolicyDocument": { "Statement": [ { @@ -399,6 +343,7 @@ "dynamodb:UpdateItem", "dynamodb:BatchWriteItem" ], + "Effect": "Allow", "Resource": [ { "Fn::Sub": [ @@ -420,48 +365,101 @@ } ] } - ], - "Effect": "Allow" + ] } ] - } + }, + "PolicyName": "ProcessingWorkflowRolePolicy4" } ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "Key": "stateMachine:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, - "OutputStore": { - "Type": "AWS::DynamoDB::Table", + "ResolverLambda": { "Properties": { - "KeySchema": [ + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "resolver.zip" + }, + "Handler": "resolver.handler", + "Role": { + "Fn::GetAtt": [ + "ResolverLambdaRole", + "Arn" + ] + }, + "Runtime": "python3.8", + "Tags": [ { - "KeyType": "HASH", - "AttributeName": "id" + "Key": "lambda:createdBy", + "Value": "SAM" } + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ResolverLambdaRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], - "TableName": "MySimpleTable", - "AttributeDefinitions": [ + "Tags": [ { - "AttributeName": "id", - "AttributeType": "S" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "BillingMode": "PAY_PER_REQUEST" - } + ] + }, + "Type": "AWS::IAM::Role" }, - "ProcessingQueue": { - "Type": "AWS::SQS::Queue" + "StarterLambda": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "starter.zip" + }, + "Handler": "starter.handler", + "Role": { + "Fn::GetAtt": [ + "StarterLambdaRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "ResolverLambdaRole": { - "Type": "AWS::IAM::Role", + "StarterLambdaRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -474,18 +472,20 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_schedule.json b/tests/translator/output/state_machine_with_schedule.json index 8730521be8..434e16586c 100644 --- a/tests/translator/output/state_machine_with_schedule.json +++ b/tests/translator/output/state_machine_with_schedule.json @@ -1,80 +1,80 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", "Properties": { - "State": "DISABLED", - "ScheduleExpression": "rate(1 minute)", - "Name": "TestSchedule", - "Description": "test schedule", + "Description": "test schedule", + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "State": "DISABLED", "Targets": [ { + "Arn": { + "Ref": "StateMachine" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", "RoleArn": { "Fn::GetAtt": [ - "StateMachineScheduleEventRole", + "StateMachineScheduleEventRole", "Arn" ] - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", - "Arn": { - "Ref": "StateMachine" } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Policies": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_schedule_dlq_retry_policy.json b/tests/translator/output/state_machine_with_schedule_dlq_retry_policy.json index 5d49175a96..95164ba8a7 100644 --- a/tests/translator/output/state_machine_with_schedule_dlq_retry_policy.json +++ b/tests/translator/output/state_machine_with_schedule_dlq_retry_policy.json @@ -1,87 +1,87 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my_state_machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineScheduleEvent": { - "Type": "AWS::Events::Rule", "Properties": { - "State": "DISABLED", - "ScheduleExpression": "rate(1 minute)", - "Name": "TestSchedule", - "Description": "test schedule", + "Description": "test schedule", + "Name": "TestSchedule", + "ScheduleExpression": "rate(1 minute)", + "State": "DISABLED", "Targets": [ { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineScheduleEventRole", - "Arn" - ] - }, - "DeadLetterConfig": { - "Arn": "Arn" - }, - "Id": "StateMachineScheduleEventStepFunctionsTarget", "Arn": { "Ref": "StateMachine" - }, + }, + "DeadLetterConfig": { + "Arn": "Arn" + }, + "Id": "StateMachineScheduleEventStepFunctionsTarget", "RetryPolicy": { - "MaximumEventAgeInSeconds": 300, + "MaximumEventAgeInSeconds": 300, "MaximumRetryAttempts": 5 + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineScheduleEventRole", + "Arn" + ] } } ] - } - }, + }, + "Type": "AWS::Events::Rule" + }, "StateMachineScheduleEventRole": { - "Type": "AWS::IAM::Role", "Properties": { - "Policies": [ - { - "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy", - "PolicyDocument": { - "Statement": [ - { - "Action": "states:StartExecution", - "Resource": { - "Ref": "StateMachine" - }, - "Effect": "Allow" - } - ] - } - } - ], "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "events.amazonaws.com" ] } } - ] - } - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my_state_machine.asl.json" - }, - "Tags": [ + ], + "Version": "2012-10-17" + }, + "Policies": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" + "PolicyDocument": { + "Statement": [ + { + "Action": "states:StartExecution", + "Effect": "Allow", + "Resource": { + "Ref": "StateMachine" + } + } + ] + }, + "PolicyName": "StateMachineScheduleEventRoleStartExecutionPolicy" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_standard_logging.json b/tests/translator/output/state_machine_with_standard_logging.json index 84a2a2e560..49e06a8430 100644 --- a/tests/translator/output/state_machine_with_standard_logging.json +++ b/tests/translator/output/state_machine_with_standard_logging.json @@ -1,180 +1,180 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { - "Handler": "hello.handler", "Code": { - "S3Bucket": "sam-demo-bucket", + "S3Bucket": "sam-demo-bucket", "S3Key": "hello.zip" - }, + }, + "Handler": "hello.handler", "Role": { "Fn::GetAtt": [ - "MyFunctionRole", + "MyFunctionRole", "Arn" ] - }, - "Runtime": "python2.7", + }, + "Runtime": "python2.7", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, - "StandardLogGroup": { - "Type": "AWS::Logs::LogGroup" - }, - "StateMachineRole": { - "Type": "AWS::IAM::Role", - "Properties": { - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "states.amazonaws.com" - ] - } - } - ] - }, - "ManagedPolicyArns": [], - "Policies": [ - { - "PolicyName": "StateMachineRolePolicy0", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": "lambda:InvokeFunction", - "Resource": { - "Fn::GetAtt": [ - "MyFunction", - "Arn" - ] - }, - "Effect": "Allow" - } - ] - } - }, - { - "PolicyName": "StateMachineRolePolicy1", - "PolicyDocument": { - "Version": "2012-10-17", - "Statement": [ - { - "Action": [ - "logs:CreateLogDelivery", - "logs:GetLogDelivery", - "logs:UpdateLogDelivery", - "logs:DeleteLogDelivery", - "logs:ListLogDeliveries", - "logs:PutResourcePolicy", - "logs:DescribeResourcePolicies", - "logs:DescribeLogGroups" - ], - "Resource": [ - "*" - ], - "Effect": "Allow" - } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ] - } - }, + }, + "Type": "AWS::Lambda::Function" + }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - }, + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } - }, + }, + "Type": "AWS::IAM::Role" + }, + "StandardLogGroup": { + "Type": "AWS::Logs::LogGroup" + }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStandardStateMachineWithLogging", + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json", + "Version": 3 + }, "DefinitionSubstitutions": { "my_lambda_arn": { "Fn::GetAtt": [ - "MyFunction", + "MyFunction", "Arn" ] } - }, + }, "LoggingConfiguration": { - "IncludeExecutionData": true, - "Level": "ALL", "Destinations": [ { "CloudWatchLogsLogGroup": { "LogGroupArn": { "Fn::GetAtt": [ - "StandardLogGroup", + "StandardLogGroup", "Arn" ] } } } + ], + "IncludeExecutionData": true, + "Level": "ALL" + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" ] - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Version": 3, - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + }, + "StateMachineName": "MyStandardStateMachineWithLogging", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, + "StateMachineRole": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "states.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:InvokeFunction", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "MyFunction", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" + }, + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "logs:CreateLogDelivery", + "logs:GetLogDelivery", + "logs:UpdateLogDelivery", + "logs:DeleteLogDelivery", + "logs:ListLogDeliveries", + "logs:PutResourcePolicy", + "logs:DescribeResourcePolicies", + "logs:DescribeLogGroups" + ], + "Effect": "Allow", + "Resource": [ + "*" + ] + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy1" + } + ], + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_tags.json b/tests/translator/output/state_machine_with_tags.json index 6016da4201..615b6ced5b 100644 --- a/tests/translator/output/state_machine_with_tags.json +++ b/tests/translator/output/state_machine_with_tags.json @@ -1,105 +1,105 @@ { "Resources": { + "StateMachine": { + "Properties": { + "DefinitionString": { + "Fn::Join": [ + "\n", + [ + "{", + " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", + " \"StartAt\": \"Hello\",", + " \"States\": {", + " \"Hello\": {", + " \"Next\": \"World\",", + " \"Result\": \"Hello\",", + " \"Type\": \"Pass\"", + " },", + " \"World\": {", + " \"End\": true,", + " \"Result\": \"World\",", + " \"Type\": \"Pass\"", + " }", + " }", + "}" + ] + ] + }, + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRole", + "Arn" + ] + }, + "StateMachineName": "MyStateMachineWithTags", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + }, + { + "Key": "TagTwo", + "Value": "ValueTwo" + }, + { + "Key": "TagOne", + "Value": "ValueOne" + } + ] + }, + "Type": "AWS::StepFunctions::StateMachine" + }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "states.amazonaws.com" ] } } - ] - }, - "ManagedPolicyArns": [], + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Action": "*", - "Resource": "*", - "Effect": "Deny" + "Action": "*", + "Effect": "Deny", + "Resource": "*" } - ] - } - } - ], - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - }, - { - "Value": "ValueTwo", - "Key": "TagTwo" - }, - { - "Value": "ValueOne", - "Key": "TagOne" + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } - ] - } - }, - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "RoleArn": { - "Fn::GetAtt": [ - "StateMachineRole", - "Arn" - ] - }, - "StateMachineName": "MyStateMachineWithTags", - "DefinitionString": { - "Fn::Join": [ - "\n", - [ - "{", - " \"Comment\": \"A Hello World example of the Amazon States Language using Pass states\",", - " \"StartAt\": \"Hello\",", - " \"States\": {", - " \"Hello\": {", - " \"Next\": \"World\",", - " \"Result\": \"Hello\",", - " \"Type\": \"Pass\"", - " },", - " \"World\": {", - " \"End\": true,", - " \"Result\": \"World\",", - " \"Type\": \"Pass\"", - " }", - " }", - "}" - ] - ] - }, - "StateMachineType": "STANDARD", + ], "Tags": [ { - "Value": "SAM", - "Key": "stateMachine:createdBy" - }, + "Key": "stateMachine:createdBy", + "Value": "SAM" + }, { - "Value": "ValueTwo", - "Key": "TagTwo" - }, + "Key": "TagTwo", + "Value": "ValueTwo" + }, { - "Value": "ValueOne", - "Key": "TagOne" + "Key": "TagOne", + "Value": "ValueOne" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_xray_policies.json b/tests/translator/output/state_machine_with_xray_policies.json index 4d23fc62d4..b72c5eae33 100644 --- a/tests/translator/output/state_machine_with_xray_policies.json +++ b/tests/translator/output/state_machine_with_xray_policies.json @@ -1,7 +1,6 @@ { "Resources": { "MyFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,13 +20,12 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, "MyFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -40,7 +38,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -51,10 +50,10 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" }, "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", "Properties": { "DefinitionS3Location": { "Bucket": "sam-demo-bucket", @@ -77,13 +76,12 @@ "TracingConfiguration": { "Enabled": true } - } + }, + "Type": "AWS::StepFunctions::StateMachine" }, "StateMachineRole": { - "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -96,20 +94,19 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/AWSXrayWriteOnlyAccess" ], "Policies": [ { - "PolicyName": "StateMachineRolePolicy0", "PolicyDocument": { - "Version": "2012-10-17", "Statement": [ { - "Effect": "Allow", "Action": "lambda:InvokeFunction", + "Effect": "Allow", "Resource": { "Fn::GetAtt": [ "MyFunction", @@ -117,8 +114,10 @@ ] } } - ] - } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRolePolicy0" } ], "Tags": [ @@ -127,7 +126,8 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/state_machine_with_xray_role.json b/tests/translator/output/state_machine_with_xray_role.json index 156d59d448..7efdf80eed 100644 --- a/tests/translator/output/state_machine_with_xray_role.json +++ b/tests/translator/output/state_machine_with_xray_role.json @@ -1,25 +1,25 @@ { - "Resources": { - "StateMachine": { - "Type": "AWS::StepFunctions::StateMachine", - "Properties": { - "Tags": [ - { - "Value": "SAM", - "Key": "stateMachine:createdBy" - } - ], - "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", - "StateMachineName": "MyStateMachineWithXRayTracing", - "TracingConfiguration": { - "Enabled": true - }, - "StateMachineType": "STANDARD", - "DefinitionS3Location": { - "Bucket": "sam-demo-bucket", - "Key": "my-state-machine.asl.json" - } - } + "Resources": { + "StateMachine": { + "Properties": { + "DefinitionS3Location": { + "Bucket": "sam-demo-bucket", + "Key": "my-state-machine.asl.json" + }, + "RoleArn": "arn:aws:iam::123456123456:role/service-role/SampleRole", + "StateMachineName": "MyStateMachineWithXRayTracing", + "StateMachineType": "STANDARD", + "Tags": [ + { + "Key": "stateMachine:createdBy", + "Value": "SAM" + } + ], + "TracingConfiguration": { + "Enabled": true } + }, + "Type": "AWS::StepFunctions::StateMachine" } -} \ No newline at end of file + } +} diff --git a/tests/translator/output/streams.json b/tests/translator/output/streams.json index b894b42069..376194c164 100644 --- a/tests/translator/output/streams.json +++ b/tests/translator/output/streams.json @@ -1,7 +1,6 @@ { "Resources": { "DynamoDBFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -15,56 +14,16 @@ ] }, "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "KinesisFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Handler": "stream.kinesis_handler", - "Role": { - "Fn::GetAtt": [ - "KinesisFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } - }, - "MSKFunction": { - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "streams.zip" - }, - "Handler": "stream.msk_handler", - "Role": { - "Fn::GetAtt": [ - "MSKFunctionRole", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [{ - "Value": "SAM", - "Key": "lambda:createdBy" - }] - } + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "DynamoDBFunctionMyDDBStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 200, "EventSourceArn": "arn:aws:dynamodb:us-west-2:012345678901:table/TestTable/stream/2015-05-11T21:21:33.291", @@ -72,39 +31,64 @@ "Ref": "DynamoDBFunction" }, "StartingPosition": "LATEST" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "DynamoDBFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaDynamoDBExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "KinesisFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" + }, + "Handler": "stream.kinesis_handler", + "Role": { + "Fn::GetAtt": [ + "KinesisFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "KinesisFunctionMyKinesisStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "BatchSize": 100, "Enabled": false, @@ -113,76 +97,106 @@ "Ref": "KinesisFunction" }, "StartingPosition": "TRIM_HORIZON" - } + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "KinesisFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaKinesisExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" + }, + "MSKFunction": { + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "streams.zip" + }, + "Handler": "stream.msk_handler", + "Role": { + "Fn::GetAtt": [ + "MSKFunctionRole", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, "MSKFunctionMyMSKStream": { - "Type": "AWS::Lambda::EventSourceMapping", "Properties": { "EventSourceArn": "arn:aws:kafka:us-west-2:012345678901:cluster/mycluster/6cc0432b-8618-4f44-bccc-e1fbd8fb7c4d-2", "FunctionName": { "Ref": "MSKFunction" }, "StartingPosition": "LATEST", - "Topics": ["Topic1"] - } + "Topics": [ + "Topic1" + ] + }, + "Type": "AWS::Lambda::EventSourceMapping" }, "MSKFunctionRole": { - "Type": "AWS::IAM::Role", "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ], + "Version": "2012-10-17" + }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", "arn:aws:iam::aws:policy/service-role/AWSLambdaMSKExecutionRole" ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], - "AssumeRolePolicyDocument": { - "Version": "2012-10-17", - "Statement": [{ - "Action": [ - "sts:AssumeRole" - ], - "Effect": "Allow", - "Principal": { - "Service": [ - "lambda.amazonaws.com" - ] - } - }] - } - } + ] + }, + "Type": "AWS::IAM::Role" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/translate_convert_metadata.json b/tests/translator/output/translate_convert_metadata.json index 2827c0cdbe..7dd6d199f8 100644 --- a/tests/translator/output/translate_convert_metadata.json +++ b/tests/translator/output/translate_convert_metadata.json @@ -1,92 +1,100 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Metadata":{"Foo": "Bar"}, - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Metadata": { + "Foo": "Bar" + }, "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Metadata": { + "Foo": "Bar" + }, + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Metadata": { + "Foo": "Bar" + }, + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Metadata":{"Foo": "Bar"}, - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Metadata":{"Foo": "Bar"}, - "Type": "AWS::Lambda::Function", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/translate_convert_no_metadata.json b/tests/translator/output/translate_convert_no_metadata.json index a3188802d1..ba64f86389 100644 --- a/tests/translator/output/translate_convert_no_metadata.json +++ b/tests/translator/output/translate_convert_no_metadata.json @@ -1,90 +1,94 @@ { "Resources": { "Images": { - "Type": "AWS::S3::Bucket", - "DependsOn": ["ThumbnailFunctionImageBucketPermission"], + "DependsOn": [ + "ThumbnailFunctionImageBucketPermission" + ], "Properties": { "NotificationConfiguration": { "LambdaConfigurations": [ { + "Event": "s3:ObjectCreated:*", "Function": { "Fn::GetAtt": [ - "ThumbnailFunction", + "ThumbnailFunction", "Arn" ] - }, - "Event": "s3:ObjectCreated:*" + } } ] } - } - }, - "ThumbnailFunctionRole": { - "Type": "AWS::IAM::Role", + }, + "Type": "AWS::S3::Bucket" + }, + "ThumbnailFunction": { + "Metadata": { + "Foo": "Bar" + }, "Properties": { - "ManagedPolicyArns": [ - "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" - ], + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "thumbnails.zip" + }, + "Handler": "index.generate_thumbails", + "Role": { + "Fn::GetAtt": [ + "ThumbnailFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } - ], + ] + }, + "Type": "AWS::Lambda::Function" + }, + "ThumbnailFunctionImageBucketPermission": { + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "ThumbnailFunction" + }, + "Principal": "s3.amazonaws.com", + "SourceAccount": { + "Ref": "AWS::AccountId" + } + }, + "Type": "AWS::Lambda::Permission" + }, + "ThumbnailFunctionRole": { + "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ "sts:AssumeRole" - ], - "Effect": "Allow", + ], + "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] } } - ] - } - } - }, - "ThumbnailFunctionImageBucketPermission": { - "Type": "AWS::Lambda::Permission", - "Properties": { - "Action": "lambda:InvokeFunction", - "SourceAccount": { - "Ref": "AWS::AccountId" - }, - "FunctionName": { - "Ref": "ThumbnailFunction" - }, - "Principal": "s3.amazonaws.com" - } - }, - "ThumbnailFunction": { - "Type": "AWS::Lambda::Function", - "Metadata":{"Foo": "Bar"}, - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "thumbnails.zip" - }, - "Handler": "index.generate_thumbails", - "Role": { - "Fn::GetAtt": [ - "ThumbnailFunctionRole", - "Arn" - ] - }, - "Runtime": "nodejs12.x", + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], "Tags": [ { - "Value": "SAM", - "Key": "lambda:createdBy" + "Key": "lambda:createdBy", + "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" } } } diff --git a/tests/translator/output/unsupported_resources.json b/tests/translator/output/unsupported_resources.json index b358015d05..5d0f51c19b 100644 --- a/tests/translator/output/unsupported_resources.json +++ b/tests/translator/output/unsupported_resources.json @@ -1,17 +1,17 @@ { "Resources": { - "UnknownTypeShouldBeAccepted": { - "Type": "AWS::Other::ABCD", + "ResourceMissingTypeShouldBeAccepted": { "Properties": { - "StageName": "Prod", - "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json" + "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json", + "StageName": "Prod" } }, - "ResourceMissingTypeShouldBeAccepted": { + "UnknownTypeShouldBeAccepted": { "Properties": { - "StageName": "Prod", - "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json" - } + "DefinitionUri": "s3://sam-demo-bucket/webpage_swagger.json", + "StageName": "Prod" + }, + "Type": "AWS::Other::ABCD" } } -} \ No newline at end of file +} diff --git a/tests/translator/output/version_deletion_policy_precedence.json b/tests/translator/output/version_deletion_policy_precedence.json index 36ab3d8420..bf773b7e16 100644 --- a/tests/translator/output/version_deletion_policy_precedence.json +++ b/tests/translator/output/version_deletion_policy_precedence.json @@ -1,7 +1,6 @@ { "Resources": { "MinimalFunction": { - "Type": "AWS::Lambda::Function", "Properties": { "Code": { "S3Bucket": "sam-demo-bucket", @@ -21,38 +20,53 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionVersion640128d35d": { - "Type": "AWS::Lambda::Version", - "DeletionPolicy": "Retain", + "MinimalFunction2": { + "DeletionPolicy": "Delete", "Properties": { - "Description": "sam-testing", - "FunctionName": { - "Ref": "MinimalFunction" - } - } + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "hello.zip" + }, + "Handler": "hello.handler", + "Role": { + "Fn::GetAtt": [ + "MinimalFunction2Role", + "Arn" + ] + }, + "Runtime": "python2.7", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + }, + "Type": "AWS::Lambda::Function" }, - "MinimalFunctionAliaslive": { - "Type": "AWS::Lambda::Alias", + "MinimalFunction2Aliaslive": { + "DeletionPolicy": "Delete", "Properties": { - "Name": "live", "FunctionName": { - "Ref": "MinimalFunction" + "Ref": "MinimalFunction2" }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunctionVersion640128d35d", + "MinimalFunction2Version640128d35d", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "MinimalFunctionRole": { - "Type": "AWS::IAM::Role", + "MinimalFunction2Role": { + "DeletionPolicy": "Delete", "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -65,7 +79,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -76,64 +91,37 @@ "Value": "SAM" } ] - } - }, - "MinimalFunction2": { - "Type": "AWS::Lambda::Function", - "DeletionPolicy": "Delete", - "Properties": { - "Code": { - "S3Bucket": "sam-demo-bucket", - "S3Key": "hello.zip" - }, - "Handler": "hello.handler", - "Role": { - "Fn::GetAtt": [ - "MinimalFunction2Role", - "Arn" - ] - }, - "Runtime": "python2.7", - "Tags": [ - { - "Key": "lambda:createdBy", - "Value": "SAM" - } - ] - } + }, + "Type": "AWS::IAM::Role" }, "MinimalFunction2Version640128d35d": { - "Type": "AWS::Lambda::Version", "DeletionPolicy": "Delete", "Properties": { "Description": "sam-testing", "FunctionName": { "Ref": "MinimalFunction2" } - } + }, + "Type": "AWS::Lambda::Version" }, - "MinimalFunction2Aliaslive": { - "Type": "AWS::Lambda::Alias", - "DeletionPolicy": "Delete", + "MinimalFunctionAliaslive": { "Properties": { - "Name": "live", "FunctionName": { - "Ref": "MinimalFunction2" + "Ref": "MinimalFunction" }, "FunctionVersion": { "Fn::GetAtt": [ - "MinimalFunction2Version640128d35d", + "MinimalFunctionVersion640128d35d", "Version" ] - } - } + }, + "Name": "live" + }, + "Type": "AWS::Lambda::Alias" }, - "MinimalFunction2Role": { - "Type": "AWS::IAM::Role", - "DeletionPolicy": "Delete", + "MinimalFunctionRole": { "Properties": { "AssumeRolePolicyDocument": { - "Version": "2012-10-17", "Statement": [ { "Action": [ @@ -146,7 +134,8 @@ ] } } - ] + ], + "Version": "2012-10-17" }, "ManagedPolicyArns": [ "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" @@ -157,7 +146,18 @@ "Value": "SAM" } ] - } + }, + "Type": "AWS::IAM::Role" + }, + "MinimalFunctionVersion640128d35d": { + "DeletionPolicy": "Retain", + "Properties": { + "Description": "sam-testing", + "FunctionName": { + "Ref": "MinimalFunction" + } + }, + "Type": "AWS::Lambda::Version" } } -} \ No newline at end of file +} diff --git a/tests/validator/output/api/error_accesslogsetting.json b/tests/validator/output/api/error_accesslogsetting.json index c9fd605fc3..3c58912b05 100644 --- a/tests/validator/output/api/error_accesslogsetting.json +++ b/tests/validator/output/api/error_accesslogsetting.json @@ -4,4 +4,4 @@ "[Resources.ApiAccessLogSettingFormatNotString.Properties.AccessLogSetting.Format] 3 is not of type 'string'", "[Resources.ApiAccessLogSettingNotObject.Properties.AccessLogSetting] 3 is not of type 'object'", "[Resources.ApiAccessLogSettingUnknownProperty.Properties.AccessLogSetting] Additional properties are not allowed ('Unknown' was unexpected)" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_auth.json b/tests/validator/output/api/error_auth.json index 35489d198a..2ce41db130 100644 --- a/tests/validator/output/api/error_auth.json +++ b/tests/validator/output/api/error_auth.json @@ -15,4 +15,4 @@ "[Resources.ApiInvokeRoleNotString.Properties.Auth.InvokeRole] 3 is not of type 'string'", "[Resources.ApiInvokeRoleNotString.Properties.Auth.InvokeRole] 3 is not one of ['CALLER_CREDENTIALS', 'NONE', 'IAMRoleArn']", "[Resources.ApiInvokeRoleNotUnknown.Properties.Auth.InvokeRole] 'UNKNOWN' is not one of ['CALLER_CREDENTIALS', 'NONE', 'IAMRoleArn']" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_auth_cognito.json b/tests/validator/output/api/error_auth_cognito.json index 6cd2814ed0..52bc389a3e 100644 --- a/tests/validator/output/api/error_auth_cognito.json +++ b/tests/validator/output/api/error_auth_cognito.json @@ -17,4 +17,4 @@ "[Resources.MyApi.Properties.Auth.Authorizers.CognitoUserPoolArnMissing] 'UserPoolArn' is a required property", "[Resources.MyApi.Properties.Auth.Authorizers.CognitoUserPoolArnNotIntrinsic.UserPoolArn] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'", "[Resources.MyApi.Properties.Auth.Authorizers.CognitoUserPoolArnNotString.UserPoolArn] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_auth_lambda.json b/tests/validator/output/api/error_auth_lambda.json index eb8498fcbf..aaf4b9cd09 100644 --- a/tests/validator/output/api/error_auth_lambda.json +++ b/tests/validator/output/api/error_auth_lambda.json @@ -14,4 +14,4 @@ "[Resources.MyApi.Properties.Auth.Authorizers.LambdaFunctionPayloadTypeNotString.FunctionPayloadType] 3 is not of type 'string'", "[Resources.MyApi.Properties.Auth.Authorizers.LambdaFunctionPayloadTypeNotString.FunctionPayloadType] 3 is not one of ['TOKEN', 'REQUEST']", "[Resources.MyApi.Properties.Auth.Authorizers.LambdaFunctionPayloadTypeUnknown.FunctionPayloadType] 'MyPayloadType' is not one of ['TOKEN', 'REQUEST']" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_auth_lambdarequest_identity.json b/tests/validator/output/api/error_auth_lambdarequest_identity.json index eb1b5216a1..8ef7181b4e 100644 --- a/tests/validator/output/api/error_auth_lambdarequest_identity.json +++ b/tests/validator/output/api/error_auth_lambdarequest_identity.json @@ -23,4 +23,4 @@ "[Resources.MyApi.Properties.Auth.Authorizers.LambdaRequestIdentityUnknown.Identity] 'ReauthorizeEvery' is a required property", "[Resources.MyApi.Properties.Auth.Authorizers.LambdaRequestIdentityUnknown.Identity] 'StageVariables' is a required property", "[Resources.MyApi.Properties.Auth.Authorizers.LambdaRequestIdentityUnknown.Identity] Additional properties are not allowed ('Unknown' was unexpected)" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_auth_lambdatoken_identity.json b/tests/validator/output/api/error_auth_lambdatoken_identity.json index 80d3e5626c..20220c940a 100644 --- a/tests/validator/output/api/error_auth_lambdatoken_identity.json +++ b/tests/validator/output/api/error_auth_lambdatoken_identity.json @@ -1,11 +1,11 @@ [ - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityEmpty.Identity] Must not be empty", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityNotObject.Identity] 3 is not of type 'object'", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryEmpty.Identity.ReauthorizeEvery] Must not be empty", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryNotInt.Identity.ReauthorizeEvery] '3' is not of type 'integer', 'intrinsic'", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryTooHigh.Identity.ReauthorizeEvery] 0 is less than the minimum of 1", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryTooLow.Identity.ReauthorizeEvery] 0 is less than the minimum of 1", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityUnknown.Identity] Additional properties are not allowed ('Unknown' was unexpected)", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityValidationExpressionEmpty.Identity.ValidationExpression] Must not be empty", - "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityValidationExpressionNotString.Identity.ValidationExpression] 3 is not of type 'string'" -] \ No newline at end of file + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityEmpty.Identity] Must not be empty", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityNotObject.Identity] 3 is not of type 'object'", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryEmpty.Identity.ReauthorizeEvery] Must not be empty", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryNotInt.Identity.ReauthorizeEvery] '3' is not of type 'integer', 'intrinsic'", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryTooHigh.Identity.ReauthorizeEvery] 0 is less than the minimum of 1", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityReauthorizeEveryTooLow.Identity.ReauthorizeEvery] 0 is less than the minimum of 1", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityUnknown.Identity] Additional properties are not allowed ('Unknown' was unexpected)", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityValidationExpressionEmpty.Identity.ValidationExpression] Must not be empty", + "[Resources.MyApi.Properties.Auth.Authorizers.LambdaTokenIdentityValidationExpressionNotString.Identity.ValidationExpression] 3 is not of type 'string'" +] diff --git a/tests/validator/output/api/error_auth_resourcepolicy.json b/tests/validator/output/api/error_auth_resourcepolicy.json index 8b1676d7f2..ec6a6d3950 100644 --- a/tests/validator/output/api/error_auth_resourcepolicy.json +++ b/tests/validator/output/api/error_auth_resourcepolicy.json @@ -53,4 +53,4 @@ "[Resources.ApiResourcePolicySourceVpcWhitelistItemNotString.Properties.Auth.ResourcePolicy.SourceVpcWhitelist.0] 3 is not of type 'string'", "[Resources.ApiResourcePolicySourceVpcWhitelistItemWrongFormat.Properties.Auth.ResourcePolicy.SourceVpcWhitelist.0] 'myvpc' must start with 'vpc-' or 'vpce-'", "[Resources.ApiResourcePolicySourceVpcWhitelistNotList.Properties.Auth.ResourcePolicy.SourceVpcWhitelist] 3 is not of type 'array'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_auth_usageplan.json b/tests/validator/output/api/error_auth_usageplan.json index 17e871b05f..fb5f117610 100644 --- a/tests/validator/output/api/error_auth_usageplan.json +++ b/tests/validator/output/api/error_auth_usageplan.json @@ -32,4 +32,4 @@ "[Resources.ApiUsagePlanNameEmpty.Properties.Auth.UsagePlan.UsagePlanName] Must not be empty", "[Resources.ApiUsagePlanNameNotString.Properties.Auth.UsagePlan.UsagePlanName] 3 is not of type 'string', 'intrinsic'", "[Resources.ApiUsagePlanNotObject.Properties.Auth.UsagePlan] 3 is not of type 'object'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_binarymediatypes.json b/tests/validator/output/api/error_binarymediatypes.json index 84dfa0925b..c7ec8398f6 100644 --- a/tests/validator/output/api/error_binarymediatypes.json +++ b/tests/validator/output/api/error_binarymediatypes.json @@ -3,4 +3,4 @@ "[Resources.ApiBinaryMediaTypesItemNotString.Properties.BinaryMediaTypes.0] 3 is not of type 'string', 'intrinsic'", "[Resources.ApiBinaryMediaTypesNotIntrinsic.Properties.BinaryMediaTypes] {'Not': 'Intrinsic'} is not of type 'array', 'intrinsic'", "[Resources.ApiBinaryMediaTypesNotList.Properties.BinaryMediaTypes] 'My binary media type' is not of type 'array', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_cachecluster.json b/tests/validator/output/api/error_cachecluster.json index 027889d301..dd8e17a4ed 100644 --- a/tests/validator/output/api/error_cachecluster.json +++ b/tests/validator/output/api/error_cachecluster.json @@ -5,4 +5,4 @@ "[Resources.ApiCacheClusterSizeEmpty.Properties.CacheClusterSize] Must not be empty", "[Resources.ApiCacheClusterSizeNotIntrinsic.Properties.CacheClusterSize] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'", "[Resources.ApiCacheClusterSizeNotString.Properties.CacheClusterSize] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_canarysetting.json b/tests/validator/output/api/error_canarysetting.json index 67ec14924a..1e7448966c 100644 --- a/tests/validator/output/api/error_canarysetting.json +++ b/tests/validator/output/api/error_canarysetting.json @@ -13,4 +13,4 @@ "[Resources.ApiStageVariableOverridesNotObject.Properties.CanarySetting.StageVariableOverrides] 'My override' is not of type 'object', 'intrinsic'", "[Resources.ApiUseStageCacheEmpty.Properties.CanarySetting.UseStageCache] Must not be empty", "[Resources.ApiUseStageCacheNotBoolean.Properties.CanarySetting.UseStageCache] 'true' is not of type 'boolean', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_cors.json b/tests/validator/output/api/error_cors.json index fe201f70c6..ccf98d08fd 100644 --- a/tests/validator/output/api/error_cors.json +++ b/tests/validator/output/api/error_cors.json @@ -10,4 +10,4 @@ "[Resources.ApiCorsNotObjectOrString.Properties.Cors] 3 is not of type 'string', 'object', 'intrinsic'", "[Resources.ApiMaxAgeEmpty.Properties.Cors.MaxAge] Must not be empty", "[Resources.ApiMaxAgeNotString.Properties.Cors.MaxAge] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_definitionbody.json b/tests/validator/output/api/error_definitionbody.json index dc262f7cd5..b708a20c59 100644 --- a/tests/validator/output/api/error_definitionbody.json +++ b/tests/validator/output/api/error_definitionbody.json @@ -1,4 +1,4 @@ [ "[Resources.ApiDefinitionBodyEmpty.Properties.DefinitionBody] Must not be empty", "[Resources.ApiDefinitionBodyNotString.Properties.DefinitionBody] 3 is not of type 'string', 'object', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_definitionuri.json b/tests/validator/output/api/error_definitionuri.json index bc3756e1ad..ff0316086c 100644 --- a/tests/validator/output/api/error_definitionuri.json +++ b/tests/validator/output/api/error_definitionuri.json @@ -6,4 +6,4 @@ "[Resources.ApiDefinitionUriKeyEmpty.Properties.DefinitionUri.Key] Must not be empty", "[Resources.ApiDefinitionUriKeyMissing.Properties.DefinitionUri] 'Key' is a required property", "[Resources.ApiDefinitionUriKeyNotString.Properties.DefinitionUri.Key] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_description.json b/tests/validator/output/api/error_description.json index 9e92d6fd0a..7bdf1b465f 100644 --- a/tests/validator/output/api/error_description.json +++ b/tests/validator/output/api/error_description.json @@ -1,4 +1,4 @@ [ "[Resources.ApiDescriptionEmpty.Properties.Description] Must not be empty", "[Resources.ApiDescriptionNotString.Properties.Description] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_domain.json b/tests/validator/output/api/error_domain.json index 253b7953f5..b83dc285d6 100644 --- a/tests/validator/output/api/error_domain.json +++ b/tests/validator/output/api/error_domain.json @@ -39,4 +39,4 @@ "[Resources.ApiRoute53IpV6Empty.Properties.Domain.Route53.IpV6] Must not be empty", "[Resources.ApiRoute53IpV6NotBoolean.Properties.Domain.Route53.IpV6] 'true' is not of type 'boolean'", "[Resources.ApiRoute53NotObject.Properties.Domain.Route53] 3 is not of type 'object'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_endpointconfiguration.json b/tests/validator/output/api/error_endpointconfiguration.json index 5cdc0c2dd0..bdac47a2c7 100644 --- a/tests/validator/output/api/error_endpointconfiguration.json +++ b/tests/validator/output/api/error_endpointconfiguration.json @@ -7,4 +7,4 @@ "[Resources.ApiEndpointConfigurationVPCEndpointIdsItemNotString.Properties.EndpointConfiguration.VPCEndpointIds.0] 3 is not of type 'string'", "[Resources.ApiEndpointConfigurationVPCEndpointIdsNotIntrinsic.Properties.EndpointConfiguration.VPCEndpointIds] {'Not': 'Intrinsic'} is not of type 'array', 'intrinsic'", "[Resources.ApiEndpointConfigurationVPCEndpointIdsNotList.Properties.EndpointConfiguration.VPCEndpointIds] 3 is not of type 'array', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_gatewayresponses.json b/tests/validator/output/api/error_gatewayresponses.json index 57e39d0225..6d1ca5eae7 100644 --- a/tests/validator/output/api/error_gatewayresponses.json +++ b/tests/validator/output/api/error_gatewayresponses.json @@ -12,4 +12,4 @@ "[Resources.ApiGatewayResponsesStatusCodeEmpty.Properties.GatewayResponses.DEFAULT_4XX.StatusCode] Must not be empty", "[Resources.ApiGatewayResponsesStatusCodeNotIntrinsic.Properties.GatewayResponses.DEFAULT_4XX.StatusCode] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'", "[Resources.ApiGatewayResponsesStatusCodeNotString.Properties.GatewayResponses.DEFAULT_4XX.StatusCode] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_methodsettings.json b/tests/validator/output/api/error_methodsettings.json index e0e6515079..9f1d569f2d 100644 --- a/tests/validator/output/api/error_methodsettings.json +++ b/tests/validator/output/api/error_methodsettings.json @@ -23,4 +23,4 @@ "[Resources.ApiMethodSettingsThrottlingBurstLimitNotInteger.Properties.MethodSettings.0.ThrottlingBurstLimit] '3' is not of type 'integer', 'intrinsic'", "[Resources.ApiMethodSettingsThrottlingRateLimitEmpty.Properties.MethodSettings.0.ThrottlingRateLimit] Must not be empty", "[Resources.ApiMethodSettingsThrottlingRateLimitNotNumber.Properties.MethodSettings.0.ThrottlingRateLimit] '3' is not of type 'number', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_minimumcompressionsize.json b/tests/validator/output/api/error_minimumcompressionsize.json index e5e5ff38fa..ca5a62dce0 100644 --- a/tests/validator/output/api/error_minimumcompressionsize.json +++ b/tests/validator/output/api/error_minimumcompressionsize.json @@ -3,4 +3,4 @@ "[Resources.ApiMinimumCompressionSizeNotIntrinsic.Properties.MinimumCompressionSize] {'Not': 'Intrinsic'} is not of type 'integer', 'intrinsic', 'null'", "[Resources.ApiMinimumCompressionSizeTooHigh.Properties.MinimumCompressionSize] 10485761 is greater than the maximum of 10485760", "[Resources.ApiMinimumCompressionSizeTooLow.Properties.MinimumCompressionSize] -1 is less than the minimum of 0" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_models.json b/tests/validator/output/api/error_models.json index ee2ce3b3df..431f83cf9e 100644 --- a/tests/validator/output/api/error_models.json +++ b/tests/validator/output/api/error_models.json @@ -2,4 +2,4 @@ "[Resources.ApiModelsEmpty.Properties.Models] Must not be empty", "[Resources.ApiModelsNotObject.Properties.Models] 3 is not of type 'object'", "[Resources.ApiModelsPropertyNotObject.Properties.Models.Test] 3 is not of type 'object'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_name.json b/tests/validator/output/api/error_name.json index fe9a96e9f7..8ab87c2e5e 100644 --- a/tests/validator/output/api/error_name.json +++ b/tests/validator/output/api/error_name.json @@ -1,4 +1,4 @@ [ "[Resources.ApiNameEmpty.Properties.Name] Must not be empty", "[Resources.ApiNameNotString.Properties.Name] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_openapiversion.json b/tests/validator/output/api/error_openapiversion.json index cfb17492a1..1bd0ce2d2e 100644 --- a/tests/validator/output/api/error_openapiversion.json +++ b/tests/validator/output/api/error_openapiversion.json @@ -3,4 +3,4 @@ "[Resources.ApiOpenApiVersion3Unknown.Properties.OpenApiVersion] '3.1' must match 2.x or 3.x.x", "[Resources.ApiOpenApiVersionEmpty.Properties.OpenApiVersion] Must not be empty", "[Resources.ApiOpenApiVersionNotString.Properties.OpenApiVersion] 3 is not of type 'string'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_properties.json b/tests/validator/output/api/error_properties.json index 1c2d941034..36436b3efd 100644 --- a/tests/validator/output/api/error_properties.json +++ b/tests/validator/output/api/error_properties.json @@ -2,4 +2,4 @@ "[Resources.ApiPropertiesEmpty.Properties] Must not be empty", "[Resources.ApiPropertiesMissing] 'Properties' is a required property", "[Resources.ApiPropertiesNotObject.Properties] 'MyProps' is not of type 'object'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_resource_attributes.json b/tests/validator/output/api/error_resource_attributes.json index fd008bc5a4..face381637 100644 --- a/tests/validator/output/api/error_resource_attributes.json +++ b/tests/validator/output/api/error_resource_attributes.json @@ -15,4 +15,4 @@ "[Resources.ApiUpdateReplacePolicyNotString.UpdateReplacePolicy] 3 is not of type 'string'", "[Resources.ApiUpdateReplacePolicyNotString.UpdateReplacePolicy] 3 is not one of ['Delete', 'Retain', 'Snapshot']", "[Resources.ApiUpdateReplacePolicyUnknown.UpdateReplacePolicy] 'SNAPSHOT' is not one of ['Delete', 'Retain', 'Snapshot']" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_stagename.json b/tests/validator/output/api/error_stagename.json index 2b559c01b5..10cff35aa9 100644 --- a/tests/validator/output/api/error_stagename.json +++ b/tests/validator/output/api/error_stagename.json @@ -3,4 +3,4 @@ "[Resources.ApiStageNameMissing.Properties] 'StageName' is a required property", "[Resources.ApiStageNameNotIntrinsic.Properties.StageName] {'Not': 'Intrinsic'} is not of type 'string', 'intrinsic'", "[Resources.ApiStageNameNotString.Properties.StageName] 3 is not of type 'string', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_tags.json b/tests/validator/output/api/error_tags.json index e8697af7ea..e7332a28f7 100644 --- a/tests/validator/output/api/error_tags.json +++ b/tests/validator/output/api/error_tags.json @@ -6,4 +6,4 @@ "[Resources.ApiTagsItemValueNotString.Properties.Tags.MyTag] 3 is not of type 'string', 'intrinsic'", "[Resources.ApiTagsItemValueTooLong.Properties.Tags.MyTag] 'MyVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongValue' is too long", "[Resources.ApiTagsNotObject.Properties.Tags] 3 is not of type 'object'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_tracingenabled.json b/tests/validator/output/api/error_tracingenabled.json index 08d70cf15d..c9b97e03d7 100644 --- a/tests/validator/output/api/error_tracingenabled.json +++ b/tests/validator/output/api/error_tracingenabled.json @@ -2,4 +2,4 @@ "[Resources.ApiTracingEnabledEmpty.Properties.TracingEnabled] Must not be empty", "[Resources.ApiTracingEnabledNotBoolean.Properties.TracingEnabled] 3 is not of type 'boolean', 'intrinsic'", "[Resources.ApiTracingEnabledNotIntrinsic.Properties.TracingEnabled] {'Not': 'Intrinsic'} is not of type 'boolean', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/api/error_variables.json b/tests/validator/output/api/error_variables.json index df6f334455..ee47fd18e6 100644 --- a/tests/validator/output/api/error_variables.json +++ b/tests/validator/output/api/error_variables.json @@ -4,4 +4,4 @@ "[Resources.ApiVariableNotString.Properties.Variables.MyVariable] 3 is not of type 'string', 'intrinsic'", "[Resources.ApiVariablesEmpty.Properties.Variables] Must not be empty", "[Resources.ApiVariablesNotObject.Properties.Variables] 3 is not of type 'object', 'intrinsic'" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_awstemplateformatversion_unknown.json b/tests/validator/output/root/error_awstemplateformatversion_unknown.json index 4442c73c13..0d818dfac2 100644 --- a/tests/validator/output/root/error_awstemplateformatversion_unknown.json +++ b/tests/validator/output/root/error_awstemplateformatversion_unknown.json @@ -1,3 +1,3 @@ [ "[AWSTemplateFormatVersion] '2021-01-26' is not one of ['2010-09-09']" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_empty_template.json b/tests/validator/output/root/error_empty_template.json index c2c20fd601..84484a42f5 100644 --- a/tests/validator/output/root/error_empty_template.json +++ b/tests/validator/output/root/error_empty_template.json @@ -1,3 +1,3 @@ [ "[.] Must not be empty" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_minimal_template_with_parameters.json b/tests/validator/output/root/error_minimal_template_with_parameters.json index 8b85bc35d8..0ae79ed68a 100644 --- a/tests/validator/output/root/error_minimal_template_with_parameters.json +++ b/tests/validator/output/root/error_minimal_template_with_parameters.json @@ -1,3 +1,3 @@ [ -"[Parameters.BadTypeParameter.Type] 'OtherThatIsNotOnTheEnumLikeTheOnesAbove' is not one of ['String', 'Number', 'List', 'CommaDelimitedList', 'AWS::EC2::AvailabilityZone::Name', 'AWS::EC2::Image::Id', 'AWS::EC2::Instance::Id', 'AWS::EC2::KeyPair::KeyName', 'AWS::EC2::SecurityGroup::GroupName', 'AWS::EC2::SecurityGroup::Id', 'AWS::EC2::Subnet::Id', 'AWS::EC2::Volume::Id', 'AWS::EC2::VPC::Id', 'AWS::Route53::HostedZone::Id', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'AWS::SSM::Parameter::Value']" -] \ No newline at end of file + "[Parameters.BadTypeParameter.Type] 'OtherThatIsNotOnTheEnumLikeTheOnesAbove' is not one of ['String', 'Number', 'List', 'CommaDelimitedList', 'AWS::EC2::AvailabilityZone::Name', 'AWS::EC2::Image::Id', 'AWS::EC2::Instance::Id', 'AWS::EC2::KeyPair::KeyName', 'AWS::EC2::SecurityGroup::GroupName', 'AWS::EC2::SecurityGroup::Id', 'AWS::EC2::Subnet::Id', 'AWS::EC2::Volume::Id', 'AWS::EC2::VPC::Id', 'AWS::Route53::HostedZone::Id', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'List', 'AWS::SSM::Parameter::Value']" +] diff --git a/tests/validator/output/root/error_resources.json b/tests/validator/output/root/error_resources.json index 81a42dbe9f..b7b85913b9 100644 --- a/tests/validator/output/root/error_resources.json +++ b/tests/validator/output/root/error_resources.json @@ -3,4 +3,4 @@ "[Resources.TypeCustomThreePartsInsteadOfTwo.Type] 'Custom::My::Custom' must use format Custom::X", "[Resources.TypeMissingSemiColon.Type] 'AWS::Serverless:Api' must use format X::Y::Z", "[Resources.TypeUnknownServerless.Type] 'AWS::Serverless::UnknownType' is not one of ['AWS::Serverless::Api', 'AWS::Serverless::Application', 'AWS::Serverless::Function', 'AWS::Serverless::HttpApi', 'AWS::Serverless::LayerVersion', 'AWS::Serverless::SimpleTable', 'AWS::Serverless::StateMachine', 'AWS::Serverless::Connector']" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_resources_empty.json b/tests/validator/output/root/error_resources_empty.json index f27a58c677..f7ee972d3e 100644 --- a/tests/validator/output/root/error_resources_empty.json +++ b/tests/validator/output/root/error_resources_empty.json @@ -1,3 +1,3 @@ [ "[Resources] Must not be empty" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_resources_missing.json b/tests/validator/output/root/error_resources_missing.json index 888154769c..1f0cda6ca0 100644 --- a/tests/validator/output/root/error_resources_missing.json +++ b/tests/validator/output/root/error_resources_missing.json @@ -1,3 +1,3 @@ [ "[.] 'Resources' is a required property" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_resources_not_object.json b/tests/validator/output/root/error_resources_not_object.json index 346de54ca0..72ed6f9434 100644 --- a/tests/validator/output/root/error_resources_not_object.json +++ b/tests/validator/output/root/error_resources_not_object.json @@ -1,3 +1,3 @@ [ "[Resources] 3 is not of type 'object'" -] \ No newline at end of file +] diff --git a/tests/validator/output/root/error_transform_empty.json b/tests/validator/output/root/error_transform_empty.json index e3d3492fd0..474f796357 100644 --- a/tests/validator/output/root/error_transform_empty.json +++ b/tests/validator/output/root/error_transform_empty.json @@ -1,3 +1,3 @@ [ "[Transform] Must not be empty" -] \ No newline at end of file +]