I have a lambda developed in Python that is working fine. Now, I decided to use the environment variables, but they always come back null. Below, project details:
-
Serverless version: 4.4.7
-
serverless.yml
service: App0001
provider:
name: aws
runtime: python3.9
region: us-east-2
stage: ${opt:stage, self:custom.defaultStage}
functions:
inicio:
handler: services/inicio/handler.inicio
events:
- http:
path: /inicio/{tenant}
method: POST
custom:
stages:
- local
- dev
- qa
- prod
environment: ${file(./env.yml)}
defaultStage: dev
stageVariables:
DATABASE_HOST: ${self:custom.environment.dbHost.${self:provider.stage}}
DATABASE_USER: ${self:custom.environment.dbUser.${self:provider.stage}}
DATABASE_PASS: ${self:custom.environment.dbPass.${self:provider.stage}}
DATABASE_NAME: ${self:custom.environment.dbName.${self:provider.stage}}
DATABASE_PORT: ${self:custom.environment.dbPort.${self:provider.stage}}
serverless-offline:
httpPort: 4000
websocketPort: 4001
lambdaPort: 4002
plugins:
-
serverless-wsgi
-
serverless-python-requirements
-
serverless-offline
-
env.yml
awsProfile:
local: default
dev: default
qa: default
prod: default
dbHost:
local: myHost
dev: myHost
qa: myHost
prod: myHost
dbUser:
local: myUser
dev: myUser
qa: myUser
prod: myUser
dbPass:
local: myPassword
dev: myPassword
qa: myPassword
prod: myPassword
dbName:
local: dev
dev: dev
qa: dev
prod: dev
dbPort:
local: ‘3306’
dev: ‘3306’
qa: ‘3306’
prod: ‘3306’
- event
event: {
body: ‘{\r\n “codAplicacao”: “9F707962-FDBE-11EE-9657-02240D86274B”\r\n}\r\n’,
headers: {
‘Content-Type’: ‘application/json’,
‘User-Agent’: ‘PostmanRuntime/7.42.0’,
Accept: ‘/’,
‘Postman-Token’: ‘75acc31b-4449-47f0-93dd-4dcacb09e80e’,
Host: ‘localhost:4000’,
‘Accept-Encoding’: ‘gzip, deflate, br’,
Connection: ‘keep-alive’,
‘Content-Length’: ‘66’
},
httpMethod: ‘POST’,
isBase64Encoded: false,
multiValueHeaders: {
‘Content-Type’: [ ‘application/json’ ],
‘User-Agent’: [ ‘PostmanRuntime/7.42.0’ ],
Accept: [ ‘/’ ],
‘Postman-Token’: [ ‘75acc31b-4449-47f0-93dd-4dcacb09e80e’ ],
Host: [ ‘localhost:4000’ ],
‘Accept-Encoding’: [ ‘gzip, deflate, br’ ],
Connection: [ ‘keep-alive’ ],
‘Content-Length’: [ ‘66’ ]
},
multiValueQueryStringParameters: null,
path: ‘/inicio/hortech’,
pathParameters: { tenant: ‘hortech’ },
queryStringParameters: null,
requestContext: {
accountId: ‘offlineContext_accountId’,
apiId: ‘offlineContext_apiId’,
domainName: ‘offlineContext_domainName’,
domainPrefix: ‘offlineContext_domainPrefix’,
extendedRequestId: ‘6a609116-bc33-49f7-90a4-f91420887126’,
httpMethod: ‘POST’,
identity: {
accessKey: null,
accountId: ‘offlineContext_accountId’,
apiKey: ‘offlineContext_apiKey’,
apiKeyId: ‘offlineContext_apiKeyId’,
caller: ‘offlineContext_caller’,
cognitoAuthenticationProvider: ‘offlineContext_cognitoAuthenticationProvider’,
cognitoAuthenticationType: ‘offlineContext_cognitoAuthenticationType’,
cognitoIdentityId: ‘offlineContext_cognitoIdentityId’,
cognitoIdentityPoolId: ‘offlineContext_cognitoIdentityPoolId’,
principalOrgId: null,
sourceIp: ‘::1’,
user: ‘offlineContext_user’,
userAgent: ‘PostmanRuntime/7.42.0’,
userArn: ‘offlineContext_userArn’
},
operationName: undefined,
path: ‘/inicio/hortech’,
protocol: ‘HTTP/1.1’,
requestId: ‘29812468-9b52-413b-a16f-2cbf8a1cff7c’,
requestTime: ‘29/Oct/2024:17:10:11 -0400’,
requestTimeEpoch: 1730236211431,
resourceId: ‘offlineContext_resourceId’,
resourcePath: ‘/dev/inicio/{tenant}’,
stage: ‘dev’
},
resource: ‘/inicio/{tenant}’,
stageVariables: null
}