Was running into similar issue, but found that adding a slight delay in script between creating lambda role and creating lambda function with role attached fixed issue. Anecdotal, but it fixed my similar issue.