diff --git a/samtranslator/model/cognito.py b/samtranslator/model/cognito.py index d44e1cf3d4..45f1645d51 100644 --- a/samtranslator/model/cognito.py +++ b/samtranslator/model/cognito.py @@ -20,7 +20,7 @@ class CognitoUserPool(Resource): "Policies": PropertyType(False, is_type(dict)), "Schema": PropertyType(False, list_of(dict)), "SmsAuthenticationMessage": PropertyType(False, is_str()), - "SmsConfiguration": PropertyType(False, list_of(dict)), + "SmsConfiguration": PropertyType(False, is_type(dict)), "SmsVerificationMessage": PropertyType(False, is_str()), "UsernameAttributes": PropertyType(False, list_of(is_str())), "UsernameConfiguration": PropertyType(False, is_type(dict)), diff --git a/samtranslator/parser/parser.py b/samtranslator/parser/parser.py index 9d07e43c24..92e5c9cada 100644 --- a/samtranslator/parser/parser.py +++ b/samtranslator/parser/parser.py @@ -18,7 +18,7 @@ def parse(self, sam_template, parameter_values, sam_plugins): @staticmethod def validate_datatypes(sam_template): - """Validates the datatype within the template """ + """Validates the datatype within the template""" if ( "Resources" not in sam_template or not isinstance(sam_template["Resources"], dict) diff --git a/tests/translator/input/congito_userpool_with_sms_configuration.yaml b/tests/translator/input/congito_userpool_with_sms_configuration.yaml new file mode 100644 index 0000000000..4677a7b8a4 --- /dev/null +++ b/tests/translator/input/congito_userpool_with_sms_configuration.yaml @@ -0,0 +1,23 @@ +Resources: + HelloWorldFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://bucket/key + Handler: app.handler + Runtime: nodejs14.x + Events: + CognitoUserPoolPreSignup: + Type: Cognito + Properties: + UserPool: + Ref: MyCognitoUserPool + Trigger: + PreSignUp + + MyCognitoUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: PreSignup + SmsConfiguration: + SnsCallerArn: !GetAtt UserPoolRole.Arn + ExternalId: !Ref ExternalId 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 new file mode 100644 index 0000000000..3c37f2d4ff --- /dev/null +++ b/tests/translator/output/aws-cn/congito_userpool_with_sms_configuration.json @@ -0,0 +1,98 @@ +{ + "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", + "S3Key": "key" + }, + "Handler": "app.handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "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": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HelloWorldFunctionCognitoPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyCognitoUserPool", + "Arn" + ] + } + } + } + } +} 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 new file mode 100644 index 0000000000..d08992be57 --- /dev/null +++ b/tests/translator/output/aws-us-gov/congito_userpool_with_sms_configuration.json @@ -0,0 +1,98 @@ +{ + "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", + "S3Key": "key" + }, + "Handler": "app.handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "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": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HelloWorldFunctionCognitoPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyCognitoUserPool", + "Arn" + ] + } + } + } + } +} diff --git a/tests/translator/output/congito_userpool_with_sms_configuration.json b/tests/translator/output/congito_userpool_with_sms_configuration.json new file mode 100644 index 0000000000..3ec561c399 --- /dev/null +++ b/tests/translator/output/congito_userpool_with_sms_configuration.json @@ -0,0 +1,98 @@ +{ + "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", + "S3Key": "key" + }, + "Handler": "app.handler", + "Role": { + "Fn::GetAtt": [ + "HelloWorldFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs14.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "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:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HelloWorldFunctionCognitoPermission": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HelloWorldFunction" + }, + "Principal": "cognito-idp.amazonaws.com", + "SourceArn": { + "Fn::GetAtt": [ + "MyCognitoUserPool", + "Arn" + ] + } + } + } + } +} diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index 577ad266e3..7f253deb1f 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -254,6 +254,7 @@ class TestTranslatorEndToEnd(AbstractTestTranslator): @parameterized.expand( itertools.product( [ + "congito_userpool_with_sms_configuration", "cognito_userpool_with_event", "s3_with_condition", "function_with_condition",