Role instead of credentials

When doing a serverless deploy, if you are using an EC2 instance to run the deploy, can you use an IAM EC2 role instead of writing key/secret to a file?

I think that it can not use with IAM EC 2 role as far as reading the document.