I run node.js app localy with this command:
$ node --icu-data-dir=node_modules/full-icu app.local.js
How to specify icu-data-dir in AWS Lambda environment?
Thanks
I run node.js app localy with this command:
$ node --icu-data-dir=node_modules/full-icu app.local.js
How to specify icu-data-dir in AWS Lambda environment?
Thanks
You should set the NODE_ICU_DATA
environment variable so that it points to a directory where the correct ICU .dat
file can be found.
If you install the full-icu
package using the node version that matches the one used by your lambdas, you should automatically get the correct .dat
file. E.g. when using the runtime nodejs10.x
:
npx -p node@10.x npm i full-icu
This installs node_modules/full-icu/
, and you should see the file icudt62l.dat
in that directory. The exact name of the file depends on the version of node you're using.
If you're deploying the whole node_modules
directory as part of your lambda, NODE_ICU_DATA=node_modules/full-icu/
(equivalent to NODE_ICU_DATA=/var/task/node_modules/full-icu
) should work. Otherwise, you can deploy just the .dat
file as part of your lambda and point NODE_ICU_DATA
at the directory where you deployed the file.
If you're still getting an error and you're sure that NODE_ICU_DATA
is correct, make sure that the .dat
file version is correct.
AWS Lambda with NodeJS 12.x seems to be compiled wth full-icu support.
exports.handler = async (event) => {
const langs = ["ar","bg","br","ch","cn","cs","da","da","de","dk","el","en","es","ev","fi","fr","hr","hu","it","ja","jp","ko","nl","no","pl","pt","pt","ro","ru","sk","sl","sv","tr"];
for (let lang of langs){
console.log(lang, Intl.DateTimeFormat(lang, {year:'numeric', month:'long', day: 'numeric'}).format(new Date()));
}
};
whith result of :
ar ٢٩ يناير ٢٠٢١
bg 29 януари 2021 г.
br 29 Genver 2021
ch January 29, 2021
cn January 29, 2021
cs 29. ledna 2021
da 29. januar 2021
da 29. januar 2021
de 29. Januar 2021
dk January 29, 2021
el 29 Ιανουαρίου 2021
en January 29, 2021
es 29 de enero de 2021
ev January 29, 2021
fi 29. tammikuuta 2021
fr 29 janvier 2021
hr 29. siječnja 2021.
hu 2021. január 29.
it 29 gennaio 2021
ja 2021年1月29日
jp January 29, 2021
ko 2021년 1월 29일
nl 29 januari 2021
no January 29, 2021
pl 29 stycznia 2021
pt 29 de janeiro de 2021
pt 29 de janeiro de 2021
ro 29 ianuarie 2021
ru 29 января 2021 г.
sk 29. januára 2021
sl 29. januar 2021
sv 29 januari 2021
tr 29 Ocak 2021
As pointed in the node.js docs, you can also use an environment variable, such as NODE_ICU_DATA=/some/directory
.
You can easily setup environment variables in your lambda instance settings.