0

I posted a question yesterday and today I have got a problem with the same project different error:

my credentials and config files look like this:

[ask-cli-Falkowsky]
aws_access_key_id =XXXXXXXXXXXX
aws_secret_access_key =XXXXXXXXXXXX

[default]
aws_access_key_id = XXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXX

[default]
output = json
region = eu-central-1

[profile ask-cli-Falkowsky]
output = json
region = eu-central-1

The Error I receive is also the Headline:

CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

The AWS Lambda function is the following:

    /* eslint-disable  func-names */
/* eslint-disable  no-console */

const Alexa = require('ask-sdk');
const dbHelper = require('./helpers/dbHelper');
const GENERAL_REPROMPT = "What would you like to do?";
const dynamoDBTableName = "dynamodb-starter";
const LaunchRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
  },
  handle(handlerInput) {
    const speechText = 'Hello there. What is your favourite movie? You can say add moviename to add your favourite movie or say list my movies to get your favourite movies.';
    const repromptText = 'What would you like to do? You can say HELP to get available options';

    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(repromptText)
      .getResponse();
  },
};

const InProgressAddMovieIntentHandler = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest' &&
      request.intent.name === 'AddMovieIntent' &&
      request.dialogState !== 'COMPLETED';
  },
  handle(handlerInput) {
    const currentIntent = handlerInput.requestEnvelope.request.intent;
    return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();
  }
}

const AddMovieIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AddMovieIntent';
  },
  async handle(handlerInput) {
    const {responseBuilder } = handlerInput;
    const userID = handlerInput.requestEnvelope.context.System.user.userId; 
    const slots = handlerInput.requestEnvelope.request.intent.slots;
    const movieName = slots.MovieName.value;
    return dbHelper.addMovie(movieName, userID)
      .then((data) => {
        const speechText = `You have added movie ${movieName}. You can say add to add another one or remove to remove movie`;
        return responseBuilder
          .speak(speechText)
          .reprompt(GENERAL_REPROMPT)
          .getResponse();
      })
      .catch((err) => {
        console.log("Error occured while saving movie", err);
        const speechText = "we cannot save your movie right now. Try again!"
        return responseBuilder
          .speak(speechText)
          .getResponse();
      })
  },
};

const GetMoviesIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GetMoviesIntent';
  },
  async handle(handlerInput) {
    const {responseBuilder } = handlerInput;
    const userID = handlerInput.requestEnvelope.context.System.user.userId; 
    return dbHelper.getMovies(userID)
      .then((data) => {
        var speechText = "Your movies are "
        if (data.length == 0) {
          speechText = "You do not have any favourite movie yet, add movie by saving add moviename "
        } else {
          speechText += data.map(e => e.movieTitle).join(", ")
        }
        return responseBuilder
          .speak(speechText)
          .reprompt(GENERAL_REPROMPT)
          .getResponse();
      })
      .catch((err) => {
        const speechText = "we cannot get your movie right now. Try again!"
        return responseBuilder
          .speak(speechText)
          .getResponse();
      })
  }
}

const InProgressRemoveMovieIntentHandler = {
  canHandle(handlerInput) {
    const request = handlerInput.requestEnvelope.request;
    return request.type === 'IntentRequest' &&
      request.intent.name === 'RemoveMovieIntent' &&
      request.dialogState !== 'COMPLETED';
  },
  handle(handlerInput) {
    const currentIntent = handlerInput.requestEnvelope.request.intent;
    return handlerInput.responseBuilder
      .addDelegateDirective(currentIntent)
      .getResponse();
  }
}

const RemoveMovieIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'RemoveMovieIntent';
  }, 
  handle(handlerInput) {
    const {responseBuilder } = handlerInput;
    const userID = handlerInput.requestEnvelope.context.System.user.userId; 
    const slots = handlerInput.requestEnvelope.request.intent.slots;
    const movieName = slots.MovieName.value;
    return dbHelper.removeMovie(movieName, userID)
      .then((data) => {
        const speechText = `You have removed movie with name ${movieName}, you can add another one by saying add`
        return responseBuilder
          .speak(speechText)
          .reprompt(GENERAL_REPROMPT)
          .getResponse();
      })
      .catch((err) => {
        const speechText = `You do not have movie with name ${movieName}, you can add it by saying add`
        return responseBuilder
          .speak(speechText)
          .reprompt(GENERAL_REPROMPT)
          .getResponse();
      })
  }
}

const HelpIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
  },
  handle(handlerInput) {
    const speechText = 'You can introduce yourself by telling me your name';

    return handlerInput.responseBuilder
      .speak(speechText)
      .reprompt(speechText)
      .getResponse();
  },
};

const CancelAndStopIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
        || handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
  },
  handle(handlerInput) {
    const speechText = 'Goodbye!';

    return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
  },
};

const SessionEndedRequestHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
  },
  handle(handlerInput) {
    console.log(`Session ended with reason: ${handlerInput.requestEnvelope.request.reason}`);

    return handlerInput.responseBuilder.getResponse();
  },
};

const ErrorHandler = {
  canHandle() {
    return true;
  },
  handle(handlerInput, error) {
    console.log(`Error handled: ${error.message}`);

    return handlerInput.responseBuilder
      .speak('Sorry, I can\'t understand the command. Please say again.')
      .reprompt('Sorry, I can\'t understand the command. Please say again.')
      .getResponse();
  },
};

const skillBuilder = Alexa.SkillBuilders.standard();

exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequestHandler,
    InProgressAddMovieIntentHandler,
    AddMovieIntentHandler,
    GetMoviesIntentHandler,
    InProgressRemoveMovieIntentHandler,
    RemoveMovieIntentHandler,
    HelpIntentHandler,
    CancelAndStopIntentHandler,
    SessionEndedRequestHandler
  )
  .addErrorHandlers(ErrorHandler)
  .withTableName(dynamoDBTableName)
  .withAutoCreateTable(true)
  .lambda();

since it is not even deployed to the my AWS account I don't think it is relevant.

when runing ask deploy I get:

lucasfalkowsky@Lucass-MacBook-Pro kneipe-temp % ask deploy             
Deploy configuration loaded from ask-resources.json
Deploy project for profile [default]

==================== Deploy Skill Metadata ====================
[Warn]: The hash of current skill package folder does not change compared to the last deploy hash result, CLI will skip the deploy of skill package.
Skill ID: amzn1.ask.skill.72df534e-2834-4ae9-b99c-bf4efe623b33

==================== Build Skill Code ====================
npm WARN dynamodb-starter@1.0.0 No repository field.

audited 18 packages in 0.722s
found 0 vulnerabilities

Skill code built successfully.
Code for region default built to /Users/lucasfalkowsky/Desktop/Hochschule/Semester_III/Interactiondesign/Block_3/kneipe-temp/.ask/lambda/custom/build.zip successfully with build flow NodeJsNpmBuildFlow.

==================== Deploy Skill Infrastructure ====================
  ✖ Deploy Alexa skill infrastructure for region "default"
[Error]: CliError: Failed to create IAM role before deploying Lambda. CredentialsError: Missing credentials in config, if using AWS_CONFIG_FILE, set AWS_SDK_LOAD_CONFIG=1

I'm slowly getting frustrated because I cant take any step forward in my university project since 2 weeks : )

Help pls

Falko
  • 33
  • 8

1 Answers1

0

Please remove your credentials from here seems like they are active now, before you get into big trouble

    $ export AWS_ACCESS_KEY_ID=<>
    $ export AWS_SECRET_ACCESS_KEY=<>
    $ aws sts get-caller-identity
    {
        "UserId": "<>",
        "Account": "<>",
        "Arn": "arn:aws:iam::<>:user/<>"
    }

if you are using windows

    set AWS_ACCESS_KEY_ID="your_key_id"
    set AWS_SECRET_ACCESS_KEY="your_secret_key"
    set AWS_REGION=<REGION_NAME>

Mac OSX/Linux

    $ export AWS_ACCESS_KEY_ID="your_key_id"
    $ export AWS_SECRET_ACCESS_KEY="your_secret_key"
    $ export AWS_REGION=<REGION_NAME>

For using the credentials there few options for how you want to use them

[1] The very first will be exporting the vars in the environment.

[2] Using profiles in the code or specifying them via command line in shared credentials file

You can find the order of loading them here

samtoddler
  • 8,463
  • 2
  • 26
  • 21
  • Yes so I did version 2. I defined my aws credentials in a credentials file and the region in the config file. (I am completely new to aws, lambda and alexa developments). What is causing this error? – Falko Jan 02 '21 at 13:04
  • can you try exporting the env var like AWS_PROFILE= and AWS_REGION= and run your code. I dont see your code for creating the clients. – samtoddler Jan 02 '21 at 13:13
  • I did export my AWS_PROFILE and REGION in the console and the same error occurres. Do you need to see some specific code to help me? – Falko Jan 02 '21 at 13:19
  • I guess the clients should be created in the lambda funktion right? Since I am using a pre built model from Babble Lab and I havent found any client creation in the Lambda funktion I suppose there is none created. I added the Lambda function to my post at the top! – Falko Jan 02 '21 at 13:34
  • is the credentials error thrown by the lambda or from your console? – samtoddler Jan 02 '21 at 13:36
  • from my console. I run ask deploy and its successfully deploey to the development console but not to aws. I also get a *CliError: Failed to create IAM role before deploying Lambda.* But I wanted to focus on one issue at a time – Falko Jan 02 '21 at 13:41
  • so I am assuming you are using aws cli to deploy your stuff to AWS. In that case you just export the credentials as environment vars as I described above depending on your host os and the run your code. The other error I assuming stems from the first one where you are not using correct credentials. – samtoddler Jan 02 '21 at 13:49
  • Well I already ran the export code and that did not do anything as well as I did check the credentials 1000 times and I already created new ones to see if that was the problem. But well nothing seems to help here. – Falko Jan 02 '21 at 13:56
  • can you do this print the output of this command and share the full command with the corresponding error in a [gist](https://gist.github.com/) I am assuming you are using linux/mac based OS – samtoddler Jan 02 '21 at 14:02
  • No error was received. I got following in my console: AWS_ACCESS_KEY_ID=XXXXXXXXXXX AWS_SECRET_ACCESS_KEY=XXXXXXXXXXX AWS_REGION=eu-central-1 – Falko Jan 02 '21 at 14:11
  • are those credentials matching what you have in your credentials file ? and can you share the full command with the corresponding here via the [gist](https://gist.github.com/) – samtoddler Jan 02 '21 at 14:25
  • I added the complete output to my question – Falko Jan 02 '21 at 15:29
  • 1
    so as per the logs >Deploy project for profile [default] it is taking the default profile already from your configured credentials. >Failed to create IAM role before deploying Lambda. this means you dont have access to create [IAM role for lambda](https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html).So all you have to do ask the IAM Administrator to give you permissions to create the role or ask him/her to create the role for you with necessary services permissions. – samtoddler Jan 02 '21 at 15:34
  • 1
    That helped me! Like you said it used the default profile to deploy it and not the profile I created, that has those permissions. Now after a long time it finaly works!! thank you so much! – Falko Jan 02 '21 at 16:10
  • 1
    glad was able to help, usually just looking at the loading sequence helps plus in case of doubt always try to print [caller-identity](https://docs.aws.amazon.com/STS/latest/APIReference/API_GetCallerIdentity.html) inside the code wherever you are doubtful which credentials are being picked up. One most important thing always try to hide credentials and account details when posting online. – samtoddler Jan 02 '21 at 16:13