title: AWS Lambda@Edge Nodejs "Environment variables are not supported."
body: <p>Motivation for doing this approach in the first place comes from Amazon: <a href="https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/" rel="noreferrer">https://aws.amazon.com/blogs/compute/resize-images-on-the-fly-with-amazon-s3-aws-lambda-and-amazon-api-gateway/</a> (before they added the 'update'...)</p>
  <p>In our AWS Lambda resize function it resizes the image and stores it the new image on S3.</p>
  <pre class="lang-js prettyprint-override"><code>const s3_bucket = process.env.s3_bucket;
  S3.putObject({
    Body: buffer,
    Bucket: s3_bucket,
    ContentType: contentType,
    CacheControl: 'max-age=31536000',
    Key: key,
    StorageClass: 'STANDARD'
  }).promise()
  </code></pre>
  <p>Now we want this to work for all our test/staging environments as well as production.. So I found &quot;Environment Variables&quot;, I though great! But when I try to deploy a new version all I get is:</p>
  <p><a href="https://i.stack.imgur.com/XTlXM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/XTlXM.png" alt="Environment variables not supported" /></a></p>
  <p>Have we set up something incorrectly in CloudFront? We are using Node version 6.10. I find it hard to believe if we have to hardcode the buckets and keep different versions of the code just to handle this? If that is the case then we wasted a lot of time using AWS Lambda...</p>
  <p><strong>Edit:</strong> What we do is take a request for an image like &quot;media/catalog/product/3/0/30123/768x/lorem.jpg&quot;, then we use the original image located at &quot;media/catalog/product/3/0/30123.jpg&quot;, resize it to 768px and webp if the browser supports that and then return the new image (if not already cached).</p>