2

I am trying to create a Lambda Function and Lambda TriggeronSQS. Following is my cloud Formation template -

Template

{
"AWSTemplateFormatVersion": "2010-09-09",
"Resources": {
    "myfunction": {
        "Type": "AWS::Lambda::Function",
        "Properties": {
            "Runtime": "java8",
            "Role": "arn:aws:iam::219560220147:role/test@123",
            "Code": {
                "S3Bucket": "lambdacode1234",
                "S3Key": "code.jar"
            },
            "MemorySize": 256,
            "Handler": "com.test.MyHandler",
            "Timeout": 25
        },
        "Metadata": {
            "AWS::CloudFormation::Designer": {
                "id": "63dae6c8-ebdb-459b-88db-02ad5dae294a"
            }
        }
    },
    "LESM34AJN": {
        "Type": "AWS::Lambda::EventSourceMapping",
        "Properties": {
            "EventSourceArn":"  arn:aws:sqs:ap-south-1:219560220147:testlambda",
            "FunctionName": {
        "Fn::GetAtt": [
            "myfunction",
            "Arn"
        ]
    },
            "BatchSize" : 1,
            "Enabled" : "TRUE"
        },
        "Metadata": {
            "AWS::CloudFormation::Designer": {
                "id": "26a65289-5f1e-41db-b94d-812d2340c945"
            }
        }
    }
},
"Mappings": {
    "RegionCodeMapping": {
        "us-east-1": {
            "regionCode": "US"
        },
        "us-west-2": {
            "regionCode": "FE"
        },
        "eu-west-1": {
            "regionCode": "EU"
        }
    }
},
"Parameters": {
    "teamname": {
        "Description": "Enter Name TeamName",
        "Type": "String",
        "AllowedPattern": "^[a-z0-9-]*$"
    },
    "env": {
        "Description": "Enter Envirment type e.g. dev,test,prod",
        "Type": "String",
        "AllowedValues": [
            "devo",
            "test",
            "prod"
        ]
    },
    "sqsARNtoTriggerLambda": {
        "Type": "String"
    },
    "codeFile": {
        "Type": "String"
    }
},
"Outputs": {
    "LambdaFunctionARN": {
        "Description": "ARN of Lambda Function",
        "Value": {
            "Fn::GetAtt": [
                "myfunction",
                "Arn"
            ]
        }
    }
}

}

ERROR

I tried creating stack via AWS Console, but receiving below error for SQS policy creation

1 validation error detected: Value ' arn:aws:sqs:ap-south-1:219560220147:testlambda' at 'eventSourceArn' failed to satisfy constraint: Member must satisfy regular expression pattern: arn:(aws[a-zA-Z0-9-]):([a-zA-Z0-9-])+:([a-z]{2}((-gov)|(-iso(b?)))?-[a-z]+-\d{1})?:(\d{12})?:(.) (Service: AWSLambda; Status Code: 400; Error Code: ValidationException; Request ID: 9a86cb1e-49e4-490d-9e48-fd93aa8d81dd)

CloudFormation Console Error

I have referred the documentation but can't figure out what the problem is? Any ideas what is wrong here?

1 Answer 1

3

Remove spaces from EventSourceArn.

Change

"LESM34AJN": {
    "Type": "AWS::Lambda::EventSourceMapping",
    "Properties": {
        "EventSourceArn":"  arn:aws:sqs:ap-south-1:219560220147:testlambda",
        "FunctionName": {
    "Fn::GetAtt": [
        "myfunction",
        "Arn"
    ]
},

To

"LESM34AJN": {
    "Type": "AWS::Lambda::EventSourceMapping",
    "Properties": {
        "EventSourceArn":"arn:aws:sqs:ap-south-1:219560220147:testlambda",
        "FunctionName": {
    "Fn::GetAtt": [
        "myfunction",
        "Arn"
    ]
},

enter image description here

From here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.