I am using aws-serverless-express for deploying an express api on aws lambda. I followed the aws-serverless-express repository example (https://github.com/awslabs/aws-serverless-express/tree/master/examples/basic-starter) to deploy the api and it works, but now I don't know how to set up environment variables in express code then after the express deployment I can see and edit those environment variables on lambda console. I didn't find any documentation about this.
1 Answers
1
votes
In the repository you mentioned, the cloudformation.yaml file has the function definition called YOUR_SERVERLESS_EXPRESS_LAMBDA_FUNCTION_NAME. you can define an attribute called Environment under that. see the example below.
YOUR_SERVERLESS_EXPRESS_LAMBDA_FUNCTION_NAME:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./
Handler: lambda.handler
MemorySize: 1024
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: nodejs8.10
Timeout: 30
Environment:
Variables:
SOME_VAR: value
Events:
ProxyApiRoot:
Type: Api
Properties:
RestApiId: !Ref ApiGatewayApi
Path: /
Method: ANY
ProxyApiGreedy:
Type: Api
Properties:
RestApiId: !Ref ApiGatewayApi
Path: /{proxy+}
Method: ANY