简体   繁体   中英

Setting lambda environmental variable using ask CLI?

How can I use the Ask CLI to set lambda function environmental variables? I tried setting them using the AWS console, but after I do that I get this error when I try to run ask deploy :

[Error]: Lambda update failed. Lambda ARN: arn:aws:lambda:us-east-1:608870357221:function:ask-custom-talk_stem-default
The Revision Id provided does not match the latest Revision Id. Call the GetFunction/GetAlias API to retrieve the latest Revision Id

Hello have you tried using --force command?

ask deploy --force

The only solution I've found is to update the variables through the AWS console and manually fetch the function's info using the AWS CLI and update the local revision id to match the revision id that's live on AWS. Here is my script:

const path = require('path');
const { readFileSync, writeFileSync } = require('fs');
const execa = require('execa');
const skillRoot = path.join(__dirname, '..');
const functionRoot = path.join(skillRoot, 'lambda', 'custom');
const askConfigPath = path.join(skillRoot, '.ask', 'config');
const askConfig = JSON.parse(readFileSync(askConfigPath, 'utf8'));
const { functionName } = askConfig.deploy_settings.default.resources.lambda[0];

async function main() {
  console.log('Downloading function info from AWS');
  const result = await execa('aws', ['lambda', 'get-function', '--function-name', functionName]);
  const functionInfo = JSON.parse(result.stdout);
  const revisionId = functionInfo.Configuration.RevisionId;

  console.log('Downloading function contents from AWS');
  await execa('ask', ['lambda', 'download', '--function', functionName], { cwd: functionRoot, stdio: 'inherit' });

  console.log('Updating skill\'s revisionId');
  askConfig.deploy_settings.default.resources.lambda[0].revisionId = revisionId;
  writeFileSync(askConfigPath, JSON.stringify(askConfig, null, 2));

  console.log('Done');
}

main();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM