How can we get environment variable form buildspecs.yml/cloudformation template in serverless.yml

How can we get the environment variable from buildspecs.yml or code pipeline(cloud formation template) in serverless.yml while codebuild or serverless deployment.
Please suggest.

Thanks,
Dilip