How to deploy AWS Lambda Function Correctly - python-3.x

Using serverless, I am trying to deploy a lambda function through AppSync. I see that my function gets deployed in the AWS Console, however, it is showing that it's over 50MB and can't display the inline editing. How do I properly deploy my lambda function?
Here's what the console looks like.

Like #LLL said, the lambda function has already been deployed. One way you can confirm that is by going to your CloudFormation stack and check the status of the lambda function. If it's successfully deployed the status should be CREATE_COMPLETE or UPDATE_COMPLETE.
If you would like to view the deployed function, you can click the Actions dropdown the page you visited in the image and click Export function. This will download all the files deployed with your lambda function.

Related

Redeployment of Azure Function does not happen

I am experimenting with an Azure Function in PowerShell to answer a simple HTTP request.
I am editing directly in the Azure Portal.
I do not understand how deployment works. I assume it should directly redeploy after "save".
When I change my code and test it within Azure Portal I get debug results in the console/log and expected results in the HTTP-Output.
However: When I call the function from a browser, it returns different results. I think these are old results, so either the function is not redeployed or some cache / proxy is fooling my browser.
How can I see if redeployment took place after "save" in the AzurePortal?
How can I check debug / console output of a real invocation?
First, I run with the default Code from the Http Trigger Function (PowerShell Runtime) - i.e., created in the Azure Portal and edited the Function Code from the Portal itself > Saved > Clicked on Run again.
If we save the function, it will just save the changes in the code. We have to run again the Function for changes made in the Code Logic for new response.
You can see how many times your function in the Azure Function App is executed, in Monitor > Invocations with more information such as Response Code for every invocation (Function Run), Execution Time,
And I have updated the Function Code two times after 1st run of the default Code. Here in the Activity Logs, you can see number of times updated the run.ps1 function code updates registered:
Updated Answer:
I have run the Azure Function App PowerShell Http Trigger in the browser tab with its function URL for 4 times and the invocations are display after 4 minutes of time because my function app is hosted in Consumption plan:
Seems the function was "disabled" - after enabling it again all works as expected!

How to create a nodejs AWS lambda function locally using vscode and not serverless or SAM CLI?

I've go through hundreds of blogs/videos/resources but nowhere it mentions how to create a simple lambda function for Nodejs REST API locally using vscode, AWS toolkit extension and AWS cli. Is there any way where I can create a simple nodejs endpoint on my local and run using above and not serverless or SAM?( There's some internal restrictions hence I can't use them)
What you need is to set up a API gateway and event trigger for your lambda that triggers whenever a HTTP request comes in. So here are steps
Look into serverless framwork where you will define a serverless.yaml file that will have configuration to mention how your lambda will get invoked (In this case, its a HTTP event)
In your IDE of choice, use serverless-offline npm package
Your IDE config will look something like this (This example uses IntelliJ IDE)
IDE config to start up Lambda in local
Once you start up the service in local, you should be able to hit the REST endpoint in local using any rest client like Postman
Instead of (4) above you could also directly invoke your lambda function in local using AWS CLI like aws lambda invoke /dev/null \ --endpoint-url http://localhost:3002 \ --function-name <Your lambda function name> \ --payload '{<Your payload>}'

How can I know whether it is running inside lambda?

I am deploying nodejs code to AWS lambda and I'd like to know how I can check whether it is running in lambda. Because I need to do something different in code between lambda and local.
AWS Lambda sets various runtime environment variables that you can leverage. You can use the following in Node.js, for example:
const isLambda = !!process.env.LAMBDA_TASK_ROOT;
console.log("Running on Lambda:", isLambda);
Note that the double bang !! converts a truthy/falsey object to a boolean (true/false).
I'd advise using a Lambda environment variable rather than attempting to check against any runtimes of the Lambda executing.
By doing this you can ensure that any infrastructure changes on the AWS side of Lambda will not affect your code.
It also allows you test it locally if you are trying to reproduce a scenario without the need to hardcode logic.

Why am I unable to set Amazon S3 as a trigger for my Serverless Lambda Function?

I am attempting to set a NodeJS Lambda function to be triggered when an image is uploaded to an Amazon S3 bucket. I have seen multiple tutorials and have the yml file set up as shown. Below is the YML config file:
functions:
image-read:
handler: handler.imageRead
events:
- s3:
bucket: <bucket-name-here>
event: s3:ObjectCreated:*
Is there something I am missing for the configuration? Is there something I need to do in an IAM role to set this up properly?
The YAML that you have here looks good but there may be some other problems.
Just to get you started:
are you deploying the function using the right credentials? (I've seen it many times that people are deploying in some other account etc. than they think - verify in the web console that it's there)
can you invoke the function in some other way? (from the serverless command line, using http trigger etc.)
do you see anything in the logs of that function? (add console.log statements to see if anything is being run)
do you see the trigger installed in the web console?
can you add trigger manually on the web console?
Try to add a simple function that would only print some logs when it is run and try to add a trigger for that function manually. If it works then try to do the same with the serverless command line but start with a simple function with just one log statement and if it works then go from there.
See also this post for more hints - S3 trigger is not registered after deployment:
https://forum.serverless.com/t/s3-trigger-is-not-registered-after-deployment/1858

Cloud Functions for Firebase error: "400, Change of function trigger type or event provider is not allowed"

When I run firebase deploy I get this error message:
functions: HTTP Error: 400, Change of function trigger type or event provider is not allowed
TL;DR
firebase functions:delete yourFunction // this can be done via the Firebase Console as well
firebase deploy
Explanation
Basically, Cloud Functions expects the same trigger for every function all the time, i.e. once it is created it has to stick to its original trigger because every function name is connected to a specific trigger. The trigger can therefore only be changed by deleting the function first and then creating it again with a different trigger.
This can now be done easily by using the functions:delete command:
firebase functions:delete yourFunction
The documentation features more advanced use cases as well.
Old solution
Solution of this is basically commenting or cutting out your function and then saving the Functions file and deploying. The function will get deleted in Firebase, but after that you can insert/uncomment your function and it will deploy just fine again. This error occurs when you take a function and change the type of trigger that it uses, i.e. HTTP, database or authentication.
Firstly cut it out
/* exports.yourFunction = someTrigger... */
And then, after deploying ("firebase deploy") replace your trigger
exports.yourFunction = anotherTrigger...
For those who stumble upon this in the future, the Cloud Functions console now offers a delete button.
You can also go to the Cloud Functions panel in the Google Cloud Platform console and delete your function from there. After that you can upload the function normally from firebase CLI. Not sure why they don't have a delete function option in the firebase console.

Resources