how to get the node_modules folder in an aws lambda function - aws-lambda

So I am learning how to create alexa skills and I have create two sucessfully following the steps below but for some reason when I follow these steps now I am missing the node_modules folder and the package.json. This is causing the following error when I test my skill:
Unable to import module 'index': Error
The steps I am following are:
- go to the aws console select lambda
- select create new function
- blueprints -> select alexa-skill-kit-sdk-factskill -> configure
- select existing role -> lambda_basic_execution
- create function
It was my understanding that the alexa-skill-kit-sdk-factskill came with these dependencies. Is there a way to add them in manually if so how? I have tried to find a console but I don't see where that is in the lambda workspace.
Here is a screen shots of the project where it did add the folder and json file
Here is on of my current project

I have had this problem, but unfortunately, Lambda console doesn't give us console to install nodejs dependencies.
So, you have to actually deploy your lambda function. There are many ways to do that, but more popular are:
Node Lambda package (for node)
Create ZIP and deploy it in console (Not recommended because of size limitation)
AWS CLI
As you're learning the Alexa Skills, I would suggest you the way Amazon suggests devs to create and organise Alexa Skill and Lambda function.
Use ASK CLI
For creating new Alexa Skill.
This will create a directory, which will have:
Skill's intent Schema
Skill's lambda function
Plus, you can pass a template to create skill for a specific template. Here is list of templates created by Amazon devs.
For eg, command for creating Skill code, for a fact-template skill
ask new [--template [template-name] [--url <url>]]
[-n|--skill-name <name>]
[-p| --profile <profile>] [--lambda-name <lambda-name>]
Using ASK CLI, will give you the advantage of deploying your skill and lambda simultaneously.
I know ASK CLI is a lot to take in so quickly, but once you get the hang of it, it is a very useful tool for Alexa developers.

You can zip the whole directory content locally and upload the zip to
lambda. But yeah you can't edit the code in the console then.
Remember that your handler file name must be mentioned as it is in Handler section.
Like if your file name is app.js then app.handler.

Related

Default AWS Lambda source code for .NET scratch build

I am trying to find the code for the default .NET AWS Lambda function. It does not appear to be one of the Lambda templates and I can't see it in the repository.
I'm talking about the code deployed when "Author from scratch" is selected - before any code is uploaded to the function.
Does anyone know where that source is made available?
I am specifically requesting the source of the .NET Lambda which returns "Hello from Lambda!" when the root Function URL is requested.

Passing code from CodePipeline to PythonFunction

I'm trying to create a CDK app that will deploy a pipeline-stack and a lambda-stack. Similar to the tutorial here. I'm trying to implement a basic CI/CD application that is triggered with every push to a Github Enterprise Repo.
I chose to use PythonFunction from (#aws-cdk/aws-lambda-python) instead of function from #aws-cdk/aws-lambda because PythonFunction builds the dependencies from requirements.txt. I have various lambdas that use different packages (like awswrangler, pandas, requests, etc.).
But, PythonFunction does not support CfnParametersCode (Where the code is passed through CDK instead of being read from an asset).
What other option do I have to pass my code from GithubEnterprise to
the PythonFunction?
If function from #aws-cdk/aws-lambda is the only option I have, how
can I include the packages from requirements.txt
This does seem like an option for #aws-cdl/aws-lambda, but how would I pass my code from Github? This example relates to building from asset code.
I apologize if I'm missing something obvious, I just started working with AWS CDK last week.
First of all I would recommend to take a look at pipelines.CdkPipeline which is able to deal with Assets. That means you can directly use lambda.Code.from_asset instead of overriding CfnParametersCode in the Pipeline.
Regarding your other question, you can deal with the requirements by installing them into your lambda folder during the build step with: pip install -r requirements.txt -t .
CfnParametersCode gives you the ability to upload your code from an S3 file.
You can do the same via lambda.Code.fromBucket.
Taking your link from the third point (https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda#bundling-asset-code) You just need to use lambda.Code.fromBucket instead of code: lambda.Code.fromAsset. Docs can be found here: https://github.com/aws/aws-cdk/tree/master/packages/%40aws-cdk/aws-lambda

AWS Lambda - How to change the handler value

Just started learning how to use AWS Lambda to put my Python codes up and I've come across an issue that is making me question my sanity. In all videos, tutorials, and forums on the subject, people seem to have an entry field to modify the name of the lambda handler. This option appears nowhere on my lambda configuration page. My code does run if I use the default naming of a "lambda_function" file and a "lambda_handler" main function inside it, but nowhere do I see an option to specify my own names.
The reason I want to specify my own names is that I am trying to be able to import user-created modules and it seems the only way to do that is to modify the handler to specify a subfolder as documented here (just putting from modulename import function, class or whatever in the main handler_function file does not appear to work.
Thanks all for all the help !!
You can change your lambda handler name.
Configuration -> Basic setting -> Handler info
You can find below Tags
See this screenshot :
For latest update remove basic setting of lambda so follow this :
Click on layer as show below in image
Check Run time setting and edit it.

Unable to find Alexa-skill-kit-sdk-factskill blueprint on aws lamda

I'm quite a beginner to Alexa skill set. Trying to add a node.js skill to Alexa following few nuggets from the internet. I have created skill on amazon developer console and trying to create aws lambda function on aws console. Surprisingly, when I tried creating a lambda function, I could not find any blueprint matching to "Alexa" keyword.
Here are the steps -:
1.Got to aws.amazon.com and log in
2. Search for the Lambda service and go to it
3. Click on Create a function
4. Click on Blueprints
5. Search for “Alexa”
I did some research and it says, changing to North. Virginia region could help but no luck so far.
Any such leads would be really appreciated.
if you are unable to find "alexa-skills-kit-nodejs-factskill" under the section "Use a blueprint",
please look for it under the section "Browse serverless app repository",it doesnt matters whatever the location you choose.
Use cloudformation application templates instead. Though they are still outdated (like the blueprints out there). My advice is that you create an Alexa Hosted Skill instead

Serverless deploying multiple functions

I've recently updated my serverless project, and I've found that many things have changed in the last few updates.
https://serverless.com/
I don't fully understand whats the correct way to have multiple lambda functions and api gateway endpoints related to the same project. With the old serverless I have every lambda and endpoint as a completely seperate function, this worked pretty well for me.
I can't seem to do this anymore, if I try my second lambda function overrides my first, presumably because my "service name" for both is the same. My service name is the same because I want both rest endpoints in the same API in API Gateway. Since serverless creates the API name based on the service name.
So then I tried to add both functions to the same "Service". this worked for the most part, except that now I need to include my custom role statement for all my functions into the same role (because this one role is now being linked to all my functions). Effectively giving more permissions to each individual function than it should have. The other issue is that all my handler files for the different functions are being put into each functions deployment bundle.
So basically, I'm not sure what is the correct approach to have multiple functions that relate to the same project but are separate in functionality. It used to make sense, now doesn't.
If anybody can give me some pointers please
Thanks
I understand your frustration. I had the same feeling until I looked deeper into the new version and formed a better understanding. One thing to note though, is the new version is not completely finished yet. So if something is completely missing, you can file an issue and have it prioritized before 1.0 is out.
You are supposed to define multiple functions under the same service under the functions: section of serverless.yml. To package these functions individually (exclude code for other functions) you will have to set individually: true under package: section. You can then use include and exclude options at the root level and at the function level as well. There's an upcoming change that will let you use glob syntax in your include and exclude options (example **/*-fn.js). You can find more about packaging here https://www.serverless.com/framework/docs/providers/aws/guide/deploying.
Not sure how to use different roles for different functions under the same service.. How did you do it with 0.5?
I was trying to find a solution for individual iam roles per function as well. I couldn't find a way to do it, but while I was looking through the documentation I found the line: "Support for separate IAM Roles per function is coming soon." on this page, so at least we know they are working on it.
The "IAM Roles Per Function" plugin for Serverless allows you to do exactly what it says on the tin: specify roles for each function. You can still use the provider-level roles as well:
By default, function level iamRoleStatements override the provider level definition. It is also possible to inherit the provider level definition by specifying the option iamRoleStatementsInherit: true
EDIT: You can also apply a predefined AWS role at both the provider and function level.

Resources