🪟 Windows TippsAndroid 17: Neue Version ist hier – Das ist alles neu(16.09.2026 um 11:40 Uhr)
🕵️ Hacking12 Best CASB Solutions Compared (2026): Features & Pricing(16.09.2026 um 09:31 Uhr)
🕵️ Hacking12 Best CIEM Tools Compared (2026): Features & Pricing(16.09.2026 um 09:37 Uhr)
🪟 Windows TippsAndroid 17: Neue Version ist hier – Das ist alles neu(16.09.2026 um 11:40 Uhr)
🕵️ Hacking12 Best CASB Solutions Compared (2026): Features & Pricing(16.09.2026 um 09:31 Uhr)
🕵️ Hacking12 Best CIEM Tools Compared (2026): Features & Pricing(16.09.2026 um 09:37 Uhr)

🔧 Programmierung 🕛 vor 2 Jahren 14 Min Lesezeit
0

Developing AWS Lambda Functions In Locally

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht




1. Introduction



In this article, we are going to learn about Lambda function creating, building, updating, and testing locally.



We can use AWS SAM to achieve this.



1.1 What is SAM



the AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications. It provides shorthand syntax to express functions, APIs, databases, and event source mappings. With just a few lines per resource, you can define the application you want and model it using YAML.



During deployment, SAM transforms and expands the SAM syntax into AWS CloudFormation syntax, enabling you to build serverless applications faster.






2. Setup the environment



2.1 Install AWS SAM CLI



You need to follow the below steps to install the on your desktop.



2.3 Authenticate AWS using AWS CLI



Follow



Step 03: Explaining project structure



** I have deleted "tests" folder. We do not need that for this lesson.



Let's start with template.yaml file.



SAM is that it deploys and maintains all of your resources, this is very similar to CloudFormation, actually this uses CloudFormation to deploy your resources and create a change set to update your resources.



template.yaml




CODE
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app2

Sample SAM Template for sam-app2

# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
MemorySize: 128

# You can add LoggingConfig parameters such as the Logformat, Log Group, and SystemLogLevel or ApplicationLogLevel. Learn more here https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-loggingconfig.
LoggingConfig:
LogFormat: JSON
Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.9
Architectures:
- x86_64
Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get

Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: API Gateway endpoint URL for Prod stage for Hello World function
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: Hello World Lambda Function ARN
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: Implicit IAM Role created for Hello World function
Value: !GetAtt HelloWorldFunctionRole.Arn







So here, we do not need the below sections. I'm removing them to keep simple of the template.yaml file.




CODE
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
HelloWorldApi:
Description: API Gateway endpoint URL for Prod stage for Hello World function
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
HelloWorldFunction:
Description: Hello World Lambda Function ARN
Value: !GetAtt HelloWorldFunction.Arn
HelloWorldFunctionIamRole:
Description: Implicit IAM Role created for Hello World function
Value: !GetAtt HelloWorldFunctionRole.Arn






and,




CODE
      Events:
HelloWorld:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /hello
Method: get






and also,




CODE
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 3
MemorySize: 128

# You can add LoggingConfig parameters such as the Logformat, Log Group, and SystemLogLevel or ApplicationLogLevel. Learn more here https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-function.html#sam-function-loggingconfig.
LoggingConfig:
LogFormat: JSON






My python runtime environment is set to Python 3.12, hence I'm changing it.



Final template.yaml




CODE
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
sam-app2

Sample SAM Template for sam-app2

Resources:
HelloWorldFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
CodeUri: hello_world/
Handler: app.lambda_handler
Runtime: python3.12
Architectures:
- x86_64







The resource name is "HelloWorldFunction"



So we have our actual lambda function called "app.py"





In the build folder within that in our lambda function this hello world function and see it has all of the requests dependencies so we could just right-click open it and zip it up and upload it in lambda it's it's everything you need all of your dependencies in one folder.








CODE
Waiting for changeset to be created..

CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
+ Add HelloWorldFunctionRole AWS::IAM::Role N/A
+ Add HelloWorldFunction AWS::Lambda::Function N/A
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Changeset created successfully. arn:aws:cloudformation:us-west-2:3xxxxxxx:changeSet/samcli-deploy11/5866b57-08875


Previewing CloudFormation changeset before deployment
======================================================
Deploy this changeset? [y/N]: Y






choose Y and press enter. It should deploy the lambda function in the role.



Now you can see the below in your CMD.




CODE
Deploy this changeset? [y/N]: Y

2024-01-06 17:18:59 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 5.0 seconds)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::CloudFormation::Stack sam-app2 User Initiated
CREATE_IN_PROGRESS AWS::IAM::Role HelloWorldFunctionRole -
CREATE_IN_PROGRESS AWS::IAM::Role HelloWorldFunctionRole Resource creation Initiated
CREATE_COMPLETE AWS::IAM::Role HelloWorldFunctionRole -
CREATE_IN_PROGRESS AWS::Lambda::Function HelloWorldFunction -
CREATE_IN_PROGRESS AWS::Lambda::Function HelloWorldFunction Resource creation Initiated
CREATE_COMPLETE AWS::Lambda::Function HelloWorldFunction -
CREATE_COMPLETE AWS::CloudFormation::Stack sam-app2 -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - sam-app2 in us-west-2






Now you can see in the CloudFormation that "sam-app2" is completed.





So we learned how to create one how to build it how to, deploy it Now we need to learn how to test it and how to update it.



Step 06: Test it and Update it.



So go back to your lambda function be sure you're not working in the build folder go back to your lambda function your app.py and let's add some stuff to it.



app.py




CODE
import json

def lambda_handler(event, context):

first_name = event['first_name']
message = event['message']

return {
"statusCode": 200,
"body": json.dumps({
"message": f"{message} {first_name}",
# "location": ip.text.replace("\n", "")
}),
}







So how do we test this locally well there's a folder here called events with an event.json file in it and this was created with our template it's got a ton of information. So we just delete that content and create a simple one.



event.json




CODE
{
"first_name": "Randika",
"message": "Hi"
}






Now we can test it locally.



Step 07: Npw we want to build it again.



Run the below command again.




CODE
sam build






You'll see it invoke the function with sam local invoke let's try that out.




CODE
sam local invoke HelloWorldFunction -e events/event.json






You see the below output,




CODE
PS C:\sam_projects\sam-app2> sam local invoke HelloWorldFunction -e events/event.json
Invoking app.lambda_handler (python3.12)
Local image is up-to-date
Using local image: public.ecr.aws/lambda/python:3.12-rapid-x86_64.

Mounting C:\sam_projects\sam-app2\.aws-sam\build\HelloWorldFunction as /var/task:ro,delegated, inside runtime container
START RequestId: 20e25543-e2c0-4ad7-9193-9a5547529f34 Version: $LATEST
END RequestId: acb97b8f-6f7d-4385-8759-740cbc67ca51
REPORT RequestId: acb97b8f-6f7d-4385-8759-740cbc67ca51 Init Duration: 0.03 ms Duration: 83.20 ms Billed Duration: 84 ms Memory Size: 128 MB Max Memory Used: 128 MB
{"statusCode": 200, "body": "{\"message\": \"Hi Randika\"}"}
[ERROR] [1704549897802] LAMBDA_RUNTIME Failed to get next invocation. No Response from endpoint
Traceback (most recent call last):
File "/var/lang/lib/python3.12/site-packages/awslambdaric/lambda_runtime_client.py", line 86, in wait_next_invocation
PS C:\Users\UPERE51\Documents\Personal\Developments\sam_projects\sam-app2>






You can see the below message in the above output.



{"statusCode": 200, "body": "{\"message\": \"Hi Randika\"}"}



That's how we test it.



Step 08:



We want to update the lambda function in AWS, we don't need to do Ssam deploy guided again, because we have this sam config tomo file that says hey here's the stack name here's the s3 bucket here's the region.



We're just going to do sam deploy.




CODE
sam deploy






Output:




CODE
PS C:\sam_projects\sam-app2> sam deploy

Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-xxxxxxx
A different default S3 bucket can be set in samconfig.toml
Or by specifying --s3-bucket explicitly.
Uploading to sam-app2/61f5bc 533019 / 533019 (100.00%)

Deploying with following values
===============================
Stack name : sam-app2
Region : us-west-2
Confirm changeset : True
Disable rollback : True
Deployment s3 bucket : aws-sam-cli-managed-default-samclisourcebucket-xxxxxxx
Capabilities : ["CAPABILITY_IAM"]
Parameter overrides : {}
Signing Profiles : {}

Initiating deployment
=====================

Uploading to sam-app2/62.template 516 / 516 (100.00%)


Waiting for changeset to be created..

CloudFormation stack changeset
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
* Modify HelloWorldFunction AWS::Lambda::Function False
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Previewing CloudFormation changeset before deployment
======================================================
Deploy this changeset? [y/N]: y

2024-01-06 19:40:53 - Waiting for stack create/update to complete

CloudFormation events from stack operations (refresh every 5.0 seconds)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
UPDATE_IN_PROGRESS AWS::CloudFormation::Stack sam-app2 User Initiated
UPDATE_IN_PROGRESS AWS::Lambda::Function HelloWorldFunction -
UPDATE_COMPLETE AWS::Lambda::Function HelloWorldFunction -
UPDATE_COMPLETE_CLEANUP_IN_PROGRESS AWS::CloudFormation::Stack sam-app2 -
UPDATE_COMPLETE AWS::CloudFormation::Stack sam-app2 -
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Successfully created/updated stack - sam-app2 in us-west-2






We should see in cloud formation the change set created. Let's go to the "sam-app2" and go to change sets and you can see the below



samapp2cloud



And that's it that's your workflow for developing lambda functions locally.

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
2 Quellen
CVE-2026-88255 | ZenHive mpp up to 0.16.1 Duplicate Submission Gate lib/mpp/replay.ex reserve_hash_atomic input validation (EUVD-2026-80256)
1 Quelle
Android 17: Neue Version ist hier – Das ist alles neu
1 Quelle
Die entscheidende Hürde: Xpeng will deutsch und nicht chinesisch sein
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Developing AWS Lambda Functions In Locally

Thematisch verwandte Begriffe: Developing, Lambda, Functions, Locally · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...