{"pageProps":{"post":{"mdxSource":"var Component=(()=>{var s=Object.create;var o=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,_=Object.prototype.hasOwnProperty;var f=(i,e)=>()=>(e||i((e={exports:{}}).exports,e),e.exports),b=(i,e)=>{for(var r in e)o(i,r,{get:e[r],enumerable:!0})},d=(i,e,r,t)=>{if(e&&typeof e==\"object\"||typeof e==\"function\")for(let a of u(e))!_.call(i,a)&&a!==r&&o(i,a,{get:()=>e[a],enumerable:!(t=m(e,a))||t.enumerable});return i};var T=(i,e,r)=>(r=i!=null?s(A(i)):{},d(e||!i||!i.__esModule?o(r,\"default\",{value:i,enumerable:!0}):r,i)),g=i=>d(o({},\"__esModule\",{value:!0}),i);var l=f((N,c)=>{c.exports=_jsx_runtime});var E={};b(E,{default:()=>v,frontmatter:()=>p});var n=T(l()),p={slug:\"aws-lambda-default-environment-variables\",date:new Date(16544736e5),title:\"Guide to default AWS Lambda environment variables\",tags:[\"AWS\",\"Lambda\"],summary:\"A walkthrough of the default AWS Lambda environment variables\",authors:[\"tlakomy\"]};function h(i){let e=Object.assign({p:\"p\",strong:\"strong\",ul:\"ul\",li:\"li\",code:\"code\",a:\"a\"},i.components);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(e.p,{children:\"AWS Lambda runtimes set a number of default environment variables during initialization of every serverless function.\"}),`\n`,(0,n.jsxs)(e.p,{children:[\"The following variables are \",(0,n.jsx)(e.strong,{children:\"reserved\"}),\" and cannot be set in your function configuration:\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"_HANDLER\"}),\" - The location of a functions's handler.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"_X_AMZN_TRACE_ID\"}),\" - \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html\",children:\"X-Ray tracing header\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_REGION\"}),\" - The region the function is running in (we all know it's \",(0,n.jsx)(e.code,{children:\"us-east-1\"}),\").\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_EXECUTION_ENV\"}),\" - The \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html\",children:\"AWS Lambda runtime identifier\"}),\". Examples: \",(0,n.jsx)(e.code,{children:\"AWS_Lambda_nodejs14.x\"}),\", \",(0,n.jsx)(e.code,{children:\"AWS_Lambda_java8\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_FUNCTION_NAME\"}),` - The name of the function (which is either \"hello world\" or IaC randomly generated one, there's no between).`]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_FUNCTION_MEMORY_SIZE\"}),\" - The amount of memory allocated to the function (e.g. 1024MB).\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_FUNCTION_VERSION\"}),\" - The version of the function (e.g. \",(0,n.jsx)(e.code,{children:\"$LATEST\"}),\").\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_INITIALIZATION_TYPE\"}),\" - The initialization type of the function, can be either \",(0,n.jsx)(e.code,{children:\"on-demand\"}),\" or \",(0,n.jsx)(e.code,{children:\"provisioned-concurrency\"}),\".\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_LOG_GROUP_NAME\"}),\" - The name of the CloudWatch log group.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_LOG_STREAM_NAME\"}),\" - The name of the CloudWatch stream.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_ACCESS_KEY\"}),\", \",(0,n.jsx)(e.code,{children:\"AWS_ACCESS_KEY_ID\"}),\", \",(0,n.jsx)(e.code,{children:\"AWS_SECRET_ACCESS_KEY\"}),\", \",(0,n.jsx)(e.code,{children:\"AWS_SESSION_TOKEN\"}),\" - The access keys obtained from the \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html\",children:\"function's execution role\"}),\". Be careful with those, read \",(0,n.jsx)(e.a,{href:\"https://github.com/puresec/sas-top-10#sas-7-insecure-application-secrets-storage\",children:\"SAS-7: Insecure Application Secrets Storage\"}),\" for guidance. This post on \",(0,n.jsx)(e.a,{href:\"https://www.trendmicro.com/fr_fr/devops/21/g/security-for-aws-lambda-serverless-applications.html\",children:\"Security for AWS Lambda Serverless Applications\"}),\" is also a good place to start.\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_RUNTIME_API\"}),\" - The host and port of the \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html\",children:\"AWS Lambda runtime API\"}),\", example: \",(0,n.jsx)(e.code,{children:\"127.0.0.1:9001\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"LAMBDA_TASK_ROOT\"}),\" - The path to your Lambda function code\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"LAMBDA_RUNTIME_DIR\"}),\" - The path to runtime libraries\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"TZ\"}),\" - The timezone information, e.g. \",(0,n.jsx)(e.code,{children:\":UTC'\"})]}),`\n`]}),`\n`,(0,n.jsxs)(e.p,{children:[\"In addition to that, AWS Lambda runtime sets additional variables that are \",(0,n.jsx)(e.strong,{children:\"not\"}),\" reserved and can be extended in your function configuration:\"]}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"LANG\"}),\" - The language of your function's runtime, e.g. \",(0,n.jsx)(e.code,{children:\"en_US.UTF-8\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"PATH\"}),\" - The execution path, e.g. \",(0,n.jsx)(e.code,{children:\"/var/lang/bin:/usr/local/bin:/usr/bin/:/bin:/opt/bin\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"LD_LIBRARY_PATH\"}),\" - The system library path, e.g. \",(0,n.jsx)(e.code,{children:\"/var/lang/lib:/lib64: /usr/lib64:/var/runtime: /var/runtime/lib:/var/task:/var/task/lib:/opt/lib\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_XRAY_CONTEXT_MISSING\"}),\" - Quoting \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime\",children:\"the docs\"}),': \"For X-Ray tracing, Lambda sets this to ',(0,n.jsx)(e.code,{children:\"LOG_ERROR\"}),' to avoid throwing runtime errors from the X-Ray SDK.\"']}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_XRAY_DAEMON_ADDRESS\"}),\" - The IP address and port of the X-Ray daemon.\"]}),`\n`]}),`\n`,(0,n.jsx)(e.p,{children:\"There are also a few runtime-specific environment variables:\"}),`\n`,(0,n.jsxs)(e.ul,{children:[`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"NODE_PATH\"}),\" - A \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html\",children:\"node.js\"}),\" env variable, containing node.js library path, e.g. \",(0,n.jsx)(e.code,{children:\"/opt/nodejs/node14/node_modules: /opt/nodejs/node_modules: /var/runtime/node_modules:/var/runtime:/var/task\"})]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"PYTHONPATH\"}),\" - The Python library path\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"GEM_PATH\"}),\" - The Ruby library path\"]}),`\n`,(0,n.jsxs)(e.li,{children:[(0,n.jsx)(e.code,{children:\"AWS_LAMBDA_DOTNET_PREJIT\"}),\" - Quoting \",(0,n.jsx)(e.a,{href:\"https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html#configuration-envvars-runtime\",children:\"the docs\"}),': \"For the .NET 3.1 runtime, set this variable to enable or disable .NET 3.1 specific runtime optimizations. Values include ',(0,n.jsx)(e.code,{children:\"always\"}),\", \",(0,n.jsx)(e.code,{children:\"never\"}),\", and \",(0,n.jsx)(e.code,{children:\"provisioned-concurrency\"}),'.\"']}),`\n`]})]})}function S(i={}){let{wrapper:e}=i.components||{};return e?(0,n.jsx)(e,Object.assign({},i,{children:(0,n.jsx)(h,i)})):h(i)}var v=S;return g(E);})();\n;return Component;","frontmatter":{"slug":"aws-lambda-default-environment-variables","date":"2022-06-06T00:00:00.000Z","title":"Guide to default AWS Lambda environment variables","tags":["AWS","Lambda"],"summary":"A walkthrough of the default AWS Lambda environment variables","authors":["tlakomy"],"fileName":"aws-lambda-default-environment-variables.mdx"}},"authors":[{"name":"Tomasz Łakomy","avatar":"/assets/blog/authors/tomasz.jpeg","twitter":"https://twitter.com/tlakomy","slug":["tlakomy"],"fileName":"tlakomy.md","date":null}],"prev":{"fileName":"aws-multi-account-benefits.mdx","slug":"aws-multi-account-benefits","date":"2022-05-23T00:00:00.000Z","title":"Benefits of multi-account strategy on AWS","tags":["AWS","CDK"],"summary":"Learn the benefits and best practices of setting up a multi-account environment on AWS","authors":["tlakomy"]},"next":{"fileName":"guide-to-lambda-function-urls.mdx","slug":"guide-to-lambda-function-urls","date":"2022-08-23T00:00:00.000Z","title":"Guide to AWS Lambda Function URLs","tags":["AWS","Lambda","serverless"],"summary":"Learn how to create dedicated HTTP(S) endpoints for Lambda functions without an API Gateway","authors":["tlakomy"]}},"__N_SSG":true}