Skip to content

Commit

Permalink
fix(sls): ensure TZ:UTC envvar automatically fixed on sls
Browse files Browse the repository at this point in the history
  • Loading branch information
uladkasach committed Jul 28, 2024
1 parent 3d86d39 commit 8b2d336
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 0 deletions.
23 changes: 23 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"husky": "8.0.3",
"jest": "29.3.1",
"prettier": "2.8.1",
"test-fns": "1.4.2",
"ts-jest": "29.1.3",
"ts-node": "10.9.2",
"type-fns": "0.8.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { given, then } from 'test-fns';

import { fix } from './serverless.yml.declapract';

describe('serverless.yml', () => {
given('a sls.yaml that needs the timezone environmental variable', () => {
const example = `
service: svc-notifications
package:
artifact: .artifact/contents.zip
plugins:
- serverless-prune-plugin
provider:
name: aws
runtime: nodejs16.x
memorySize: 1024 # optional, in MB, default is 1024
timeout: 60 # default timeout to 1min, for resilience against increased cold start times; individual functions can override this
stage: \${opt:stage}
stackTags:
app: ahbode
environment: \${self:provider.stage}
product: \${self:service}
environment:
NODE_ENV: production # deploy with production optimizations of all resources, to make \`dev\` and \`prod\` stage deployments equivalent functionally (i.e., the same code paths in dev and prod)
STAGE: \${self:provider.stage} # deploy specifying which stage we're targeting, to enable targeting the correct config + resources (e.g., hit dev db -vs- prod db)
AWS_NODEJS_CONNECTION_REUSE_ENABLED: true # https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html
deploymentBucket: serverless-deployment-xyz-\${self:provider.stage}
`.trim();
then('it should be able to add the timezone env var', async () => {
const fixed = await fix(example, {} as any);
expect(fixed.contents).toContain('TZ: UTC');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const fix: FileFixFunction = (contents) => {
'## allow invocation of other lambdas',
'# allow invocation of other lambdas',
)
.replace(
'environment:\n NODE_ENV:',
'environment:\n TZ: UTC # guarantee that utc timezone will be used explicitly, to facilitate a pit of success\n NODE_ENV:',
)
.replace(
'NODE_ENV: ${self:custom.stageToNodeEnvMapping.${self:provider.stage}}\n deploymentBucket',
'NODE_ENV: ${self:custom.stageToNodeEnvMapping.${self:provider.stage}}\n AWS_NODEJS_CONNECTION_REUSE_ENABLED: true # https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/node-reusing-connections.html\n deploymentBucket',
Expand Down

0 comments on commit 8b2d336

Please sign in to comment.