2022-10-06 14:10:53 -06:00
# Lambda code examples for the SDK for Ruby
2023-05-19 13:23:56 -06:00
2022-10-06 14:10:53 -06:00
## Overview
2022-09-19 09:05:20 -06:00
2023-05-19 13:23:56 -06:00
Shows how to use the AWS SDK for Ruby to work with AWS Lambda.
<!--custom.overview.start-->
<!--custom.overview.end-->
2024-01-04 13:25:48 -05:00
_ Lambda allows you to run code without provisioning or managing servers. _
2023-05-19 13:23:56 -06:00
## ⚠ Important
2022-10-06 14:10:53 -06:00
2024-01-04 13:25:48 -05:00
* Running this code might result in charges to your AWS account. For more details, see [AWS Pricing ](https://aws.amazon.com/pricing/ ) and [Free Tier ](https://aws.amazon.com/free/ ).
2022-10-06 14:10:53 -06:00
* Running the tests might result in charges to your AWS account.
2023-05-19 13:23:56 -06:00
* We recommend that you grant your code least privilege. At most, grant only the minimum permissions required to perform the task. For more information, see [Grant least privilege ](https://docs.aws.amazon.com/IAM/latest/UserGuide/best-practices.html#grant-least-privilege ).
2022-10-21 10:23:10 -06:00
* This code is not tested in every AWS Region. For more information, see [AWS Regional Services ](https://aws.amazon.com/about-aws/global-infrastructure/regional-product-services ).
2022-09-19 09:05:20 -06:00
2023-05-19 13:23:56 -06:00
<!--custom.important.start-->
<!--custom.important.end-->
2022-09-19 09:05:20 -06:00
## Code examples
2023-05-19 13:23:56 -06:00
### Prerequisites
For prerequisites, see the [README ](../../README.md#Prerequisites ) in the `ruby` folder.
<!--custom.prerequisites.start-->
<!--custom.prerequisites.end-->
2024-07-09 11:47:20 -04:00
### Get started
- [Hello Lambda ](hello/hello_lambda.rb#L4 ) (`ListFunctions` )
2024-10-24 09:34:43 -04:00
### Basics
Code examples that show you how to perform the essential operations within a service.
- [Learn the basics ](lambda_basics.rb )
2022-10-21 10:23:10 -06:00
### Single actions
2023-05-19 13:23:56 -06:00
2022-10-06 14:10:53 -06:00
Code excerpts that show you how to call individual service functions.
2024-09-25 15:25:54 -04:00
- [CreateFunction ](lambda_basics.rb#L131 )
- [DeleteFunction ](lambda_basics.rb#L281 )
- [GetFunction ](lambda_basics.rb#L114 )
- [Invoke ](lambda_basics.rb#L166 )
- [ListFunctions ](lambda_basics.rb#L266 )
- [UpdateFunctionCode ](lambda_basics.rb#L241 )
- [UpdateFunctionConfiguration ](lambda_basics.rb#L216 )
2022-10-21 10:23:10 -06:00
2024-01-04 13:25:48 -05:00
<!--custom.examples.start-->
<!--custom.examples.end-->
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
## Run the examples
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
### Instructions
2022-10-21 10:23:10 -06:00
2023-05-19 13:23:56 -06:00
<!--custom.instructions.start-->
The quickest way to interact with this example code is to invoke a [Scenario ](#Scenarios ) from your command line. For example, `ruby some_scenario.rb` will invoke `some_scenario.rb` .
<!--custom.instructions.end-->
2022-10-21 10:23:10 -06:00
2024-07-09 11:47:20 -04:00
#### Hello Lambda
This example shows you how to get started using Lambda.
```
ruby hello/hello_lambda.rb
```
2022-10-21 10:23:10 -06:00
2024-10-24 09:34:43 -04:00
#### Learn the basics
2022-09-19 09:05:20 -06:00
2023-05-19 13:23:56 -06:00
This example shows you how to do the following:
2022-10-06 14:10:53 -06:00
2024-01-04 13:25:48 -05:00
- Create an IAM role and Lambda function, then upload handler code.
- Invoke the function with a single parameter and get results.
- Update the function code and configure with an environment variable.
- Invoke the function with new parameters and get results. Display the returned execution log.
- List the functions for your account, then clean up resources.
2022-10-06 14:10:53 -06:00
2024-10-24 09:34:43 -04:00
<!--custom.basic_prereqs.lambda_Scenario_GettingStartedFunctions.start-->
<!--custom.basic_prereqs.lambda_Scenario_GettingStartedFunctions.end-->
2022-10-06 14:10:53 -06:00
2023-05-19 13:23:56 -06:00
Start the example by running the following at a command prompt:
2022-10-06 14:10:53 -06:00
2023-05-19 13:23:56 -06:00
```
ruby lambda_basics.rb
```
2022-10-06 14:10:53 -06:00
2024-10-24 09:34:43 -04:00
<!--custom.basics.lambda_Scenario_GettingStartedFunctions.start-->
<!--custom.basics.lambda_Scenario_GettingStartedFunctions.end-->
2022-09-19 09:05:20 -06:00
2023-05-19 13:23:56 -06:00
### Tests
2022-09-19 09:05:20 -06:00
2023-05-19 13:23:56 -06:00
⚠ Running tests might result in charges to your AWS account.
2022-09-19 09:05:20 -06:00
2022-10-06 14:10:53 -06:00
2023-05-19 13:23:56 -06:00
To find instructions for running these tests, see the [README ](../../README.md#Tests )
in the `ruby` folder.
2022-09-19 09:05:20 -06:00
2023-05-19 13:23:56 -06:00
<!--custom.tests.start-->
## Contribute
Code examples thrive on community contribution.
To learn more about the contributing process, see [CONTRIBUTING.md ](../../../CONTRIBUTING.md ).
<!--custom.tests.end-->
2022-10-06 14:10:53 -06:00
2022-10-21 10:23:10 -06:00
## Additional resources
2022-09-19 09:05:20 -06:00
2024-01-04 13:25:48 -05:00
- [Lambda Developer Guide ](https://docs.aws.amazon.com/lambda/latest/dg/welcome.html )
- [Lambda API Reference ](https://docs.aws.amazon.com/lambda/latest/dg/API_Reference.html )
- [SDK for Ruby Lambda reference ](https://docs.aws.amazon.com/sdk-for-ruby/v3/api/Aws/Lambda.html )
2023-05-19 13:23:56 -06:00
<!--custom.resources.start-->
<!--custom.resources.end-->
---
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0