Unable to connect an instance during packer build

Hi Everyone,

Could someone help me to troubleshoot below error during packer AMI build for AWS? It stucks at
Using SSH communicator to connect: localhost
Waiting for SSH to become available..
I am using session_manager as ssh_interface.
When i specify an iam_instance_profile - all goes good. But when i specify the below. I am getting this error. Please let me know if someone already faced this problem - is it known issue with packer or is there any workaround?

temporary_iam_instance_profile_policy_document {

Version = "2012-10-17"



Statement {

  Effect   = "Allow"

  Action   = \[

    "ssm:DescribeAssociation",

    "ssm:GetDeployablePatchSnapshotForInstance",

    "ssm:GetDocument",

    "ssm:DescribeDocument",

    "ssm:GetManifest",

    "ssm:GetParameter",

    "ssm:GetParameters",

    "ssm:ListAssociations",

    "ssm:ListInstanceAssociations",

    "ssm:PutInventory",

    "ssm:PutComplianceItems",

    "ssm:PutConfigurePackageResult",

    "ssm:UpdateAssociationStatus",

    "ssm:UpdateInstanceAssociationStatus",

    "ssm:UpdateInstanceInformation"

  \]

  Resource = \["\*"\]

}



Statement {

  Effect   = "Allow"

  Action   = \[

    "ssmmessages:CreateControlChannel",

    "ssmmessages:CreateDataChannel",

    "ssmmessages:OpenControlChannel",

    "ssmmessages:OpenDataChannel"

  \]

  Resource = \["\*"\]

}



Statement {

  Effect   = "Allow"

  Action   = \[

    "ec2messages:AcknowledgeMessage",

    "ec2messages:DeleteMessage",

    "ec2messages:FailMessage",

    "ec2messages:GetEndpoint",

    "ec2messages:GetMessages",

    "ec2messages:SendReply"

  \]

  Resource = \["\*"\]

}

}