While I'm not familiar with the way Serverless works, what you are looking for is an IAM Role.
You can assign a role to an EC2 instances or AWS Lambda functions so that code that you write that uses the AWS SDK will automatically be able to retrieve AWS credentials with the permissions associated with that role. For AWS Lambda and your use case you will want to grant the role you assign AWS Lambda access to the DynamoDB tables it requires to run.
This can be deceivingly simple to use, you simply do not provide credentials and it just works (as long as the role has the correct permissions)! The AWS SDK takes care of everything for you by automatically retrieving credentials that are associated with the Role.
From the link you provided the specific question that references this under the best practice is Credentials from IAM Roles for EC2 Instances where it refers to EC2 instances, but this also applies to AWS Lambda.