Francesco Castiglione
Francesco Castiglione

Reputation: 33

Google Assistant Skill for Alexa

I found a guide on how to create a skill for Alexa that made me use Google as a search engine (thus integrating Google Assistant into Alexa). The problem is that Amazon has upgraded to nodejs 16.x, while the guides are stuck on previous versions. How can I solve the problem?

Running a test using Lambda on Amazon AWS, the error it gives me is the following:

{
  "errorMessage": "RequestId: ab04002d-67e6-4144-9c1f-94987a0b8e5e Error: Runtime exited with error: exit status 7",
  "errorType": "Runtime.ExitError"
}

nNODE_MODULE_VERSION 72. This version of Node.js requires\nNODE_MODULE_VERSION 93. Please try re-compiling or re-installing\nthe module (for instance, using `npm rebuild` or `npm install`).","code":"ERR_DLOPEN_FAILED","stack":["Error: The module '/var/task/node_modules/@suldashi/lame/build/Release/bindings.node'","was compiled against a different Node.js version using","NODE_MODULE_VERSION 72. This version of Node.js requires","NODE_MODULE_VERSION 93.

I think I need to modify the Lambda function code by uploading an updated zip file, but I don't know how or where to get it.

For example, I uploaded this zip file (github: https://github.com/rokmohar/alexa-assistant/releases) to update Node to version 12.x and update Node packages. Is it possible to do a similar thing with nodejs 16.x?

I believe the problem is in this code:

{
"AWSTemplateFormatVersion": "2010-09-09",
"Metadata":{
    "License": "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License"
},
Description: "This AWS CloudFormation Template is provided for users to install the Alexa Google Assistant skill. It is provided under the Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License. This means that you may use this template provided that it is not for commercial use. You may not host instructions that use this CloudFormation template if you receive monetisation from that page, for example embedded adverts",
"Mappings": {
    "RegionMap": {
        "us-east-1": {
            "BUCKET": "alexagoogleassistantskilluseast1"
        },
        "eu-west-1": {
            "BUCKET": "alexagoogleassistantskilleuwest1"
        }
    }
},
"Conditions": {
    "CorrectAWSRegion": {
        "Fn::Or": [
            {
                "Fn::Equals": [
                    {
                        "Ref": "AWS::Region"
                    },
                    "eu-west-1"
                ]
            },
            {
                "Fn::Equals": [
                    {
                        "Ref": "AWS::Region"
                    },
                    "us-east-1"
                ]
            }
        ]
    },
    "IncorrectAWSRegion": {
        "Fn::Not": [
            {
                "Condition": "CorrectAWSRegion"
            }
        ]
    }
},
"Resources": {
    "S3Bucket": {
        "Type": "AWS::S3::Bucket",
        "Condition": "CorrectAWSRegion",
        "Properties": {
            
        }
    },
    "DynamoDBtable": {
            "Type" : "AWS::DynamoDB::Table",
        "Condition": "CorrectAWSRegion",
            "Properties" : {
                "AttributeDefinitions" : [
                  {
                    "AttributeName" : "userId",
                    "AttributeType" : "S"   
                  }
                ],
              "KeySchema" : 
                  [
                      {
                        "AttributeName" : "userId",
                        "KeyType" : "HASH"
                      }
                  ]
                
                ,
              "ProvisionedThroughput" : {
                "ReadCapacityUnits" : 5,
                "WriteCapacityUnits" : 5
              },
              "TableName": "AlexaAssistantSkillSettings"                       
            }
        
    },
    "LambdaFunctionRole": {
        "Type": "AWS::IAM::Role",
        "Condition": "CorrectAWSRegion",
        "Properties": {
            "AssumeRolePolicyDocument": {
                "Version": "2012-10-17",
                "Statement": [
                    {
                        "Effect": "Allow",
                        "Principal": {
                            "Service": [
                                "lambda.amazonaws.com"
                            ]
                        },
                        "Action": [
                            "sts:AssumeRole"
                        ]
                    }
                ]
            },
            "Path": "/",
            "Policies": [
                {
                    "PolicyName": "GoogleAssistantPolicy",
                    "PolicyDocument": {
                        "Version": "2012-10-17",
                        "Statement": [
                            {
                                "Sid": "AllowLogging",
                                "Effect": "Allow",
                                "Action": [
                                    "logs:CreateLogGroup",
                                    "logs:CreateLogStream",
                                    "logs:PutLogEvents"
                                ],
                                "Resource": [
                                    "*"
                                ]
                            },
                            {
                                "Effect": "Allow",
                                "Action": "s3:*",
                                "Resource": [
                                    {
                                        "Fn::Join": [
                                            "",
                                            [
                                                {
                                                    "Fn::GetAtt": [
                                                        "S3Bucket",
                                                        "Arn"
                                                    ]
                                                },
                                                "*"
                                            ]
                                        ]
                                    }
                                ]
                            },
                            {
                                "Effect": "Allow",
                                "Action": "dynamodb:*",
                                "Resource": [
                                    {
                                        "Fn::Join": [
                                            "",
                                            [
                                                {
                                                    "Fn::GetAtt": [
                                                        "DynamoDBtable",
                                                        "Arn"
                                                    ]
                                                },
                                                "*"
                                            ]
                                        ]
                                    }
                                ]
                            }
                            
                        ]
                    }
                }
            ]
        }
    },
    "AlexaSkillFunction": {
        "Type": "AWS::Lambda::Function",
        "Condition": "CorrectAWSRegion",
        "Properties": {
            "FunctionName": "alexa-assistant-skill-function",
            "Handler": "index.handler",
            "Role": {
                "Fn::GetAtt": [
                    "LambdaFunctionRole",
                    "Arn"
                ]
            },
            "Description": "Alexa Skill code for the Google Assistant Skill",
            "Code": {
                "S3Bucket": {
                    "Fn::FindInMap": [
                        "RegionMap",
                        {
                            "Ref": "AWS::Region"
                        },
                        "BUCKET"
                    ]
                },
                "S3Key": "index_1.2.zip"
            },
            "Runtime": "nodejs16.x",
            "Timeout": "10",
            "MemorySize": "1344",
            "Environment": {
                "Variables": {
                    "S3_BUCKET": {
                        "Ref": "S3Bucket"
                    },
                    "API_ENDPOINT": "embeddedassistant.googleapis.com"
                }
            }
        }
    },
    "AlexaSkillFunctionPermissions": {
        "Type": "AWS::Lambda::Permission",
        "Condition": "CorrectAWSRegion",
        "Properties": {
            "FunctionName": {
                "Ref": "AlexaSkillFunction"
            },
            "Action": "lambda:InvokeFunction",
            "Principal": "alexa-appkit.amazon.com"
        }
    }
},
"Outputs": {
    "FunctionARN": {
        "Condition": "CorrectAWSRegion",
        "Value": {
            "Fn::GetAtt": [
                "AlexaSkillFunction",
                "Arn"
            ]
        },
        "Description": "Lambda function ARN to be placed in the Amazon Developer Portal"
    },
    "FunctionError": {
        "Condition": "IncorrectAWSRegion",
        "Value": "Incorrect AWS Region!!! Must be US-East(N. VIRGINIA) or EU(Ireland)",
        "Description": "You must Select US-EAST (North Virgina) if you are located in North America or EU (Ireland) if you are located elsewhere"
    }
}

}

Thanks for the help.

Upvotes: 1

Views: 378

Answers (1)

Rok Mohar
Rok Mohar

Reputation: 31

I am the autor of the package above. It was just updated to use NodeJs 18.x and latest ASK SKD v2. Can you try to setup with the latest version (currently 1.5.0) and let me know if it works for you.

Upvotes: 1

Related Questions