AWS Lambda Developer Guide Supplementary Resources

repository·main·Indexed 25 days ago

https://github.com/awsdocs/aws-lambda-developer-guide

A collection of supplementary resources for the AWS Lambda Developer Guide, featuring sample IAM policies for console triggers, execution role templates, and blueprint policies. The repository includes sample applications for C# (.NET Core 8.0), Go, Java, and Node.js 18, along with AWS CloudFormation templates for provisioning Lambda functions and VPC network resources.

Tokens
9.4K
Snippets
34
Records
56
Agent score
82%

What's inside aws-lambda-developer-guide

  1. Explore AWS Lambda developer resources

    main

    The AWS Lambda Developer Guide repository provides supplementary resources for developers, including sample permissions policies, application examples, and infrastructure templates.

    • Sample IAM Policies: Located in ./iam-policies, these provide sample permissions policies for cross-service use cases.
    • Sample Applications: Located in ./sample-apps, these demonstrate various features and use cases for the AWS Lambda service and its managed runtimes.
    • CloudFormation Templates: Located in ./templates, these contain AWS CloudFormation templates for provisioning Lambda functions and VPC network resources.
  2. Setup and deploy the Blank function (Go) application

    main

    Follow these steps to prepare and deploy the application:

    1. Clone the repository and navigate to the sample directory:

      git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
      cd aws-lambda-developer-guide/sample-apps/blank-go
    2. Create a deployment bucket: Run 1-create-bucket.sh to create a new S3 bucket for deployment artifacts.

      ./1-create-bucket.sh
    3. Deploy the application: Run 2-deploy.sh. This script uses AWS CloudFormation to deploy the Lambda functions and an IAM role. If the stack already exists, it will update it.

      ./2-deploy.sh
    # Clone and enter directory
    git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
    cd aws-lambda-developer-guide/sample-apps/blank-go
    
    # Create bucket
    ./1-create-bucket.sh
    
    # Deploy
    ./2-deploy.sh
  3. View AWS X-Ray traces for the C# function

    main

    The application uses AWS X-Ray to trace requests. To visualize the service map and analyze function performance:

    1. Open the X-Ray console.
    2. Locate the service map showing the function managing spot instances in Amazon EC2.
    3. Choose a node in the main function graph.
    4. Select View traces to see a list of available traces.
    5. Select any trace to view a timeline breakdown of the work performed by the function.
  4. Configure different Lambda Handler classes

    main

    The sample includes several handler implementations in src/main/java/example. To switch between them, update the Handler property in the AWS SAM template (template.yml or template-mvn.yaml).

    Available Handlers

    • example.Handler: Takes Map<String,String>
    • example.HandlerInteger: Takes Integer
    • example.HandlerList: Takes List<Integer>
    • example.HandlerDivide: Takes List<Integer> (two integers)
    • example.HandlerStream: Takes InputStream and OutputStream
    • example.HandlerString: Takes String
    • example.HandlerWeatherData: Takes a custom type

    Example Configuration

    To use the list handler, update your template as follows:

    Properties:
      CodeUri: build/distributions/java-basic.zip
      Handler: example.HandlerList

    Testing non-JSON handlers

    After deploying a change, if the handler does not take a JSON object as input, pass the type (string, int, list, or divide) as an argument to the invoke script:

    ./3-invoke.sh list
  5. Setup and deploy Blank function with layer (C#)

    main

    Follow these steps to set up, build, and deploy the C# Lambda function and its associated layer.

    1. Clone the repository and navigate to the project directory:

      git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
      cd aws-lambda-developer-guide/sample-apps/blank-csharp
    2. Create an S3 bucket and IAM role: Run the following script to create a new bucket for deployment artifacts and the necessary IAM role.

      ./1-create-bucket.sh
    3. Build the Lambda layer: Run this script to build the Lambda layer containing runtime dependencies and upload it to the S3 bucket created in the previous step.

      ./2-build-layer.sh
    4. Deploy the application: Run this script to deploy the Lambda function using the .NET Amazon Lambda Tools. It uses default settings from src/aws-lambda-tools-defaults.json.

      ./3-deploy.sh
    5. Invoke the function: Run the following script to test the function. Press CTRL+C to exit after a few invocations.

      ./4-invoke.sh
    # Sequence of setup and deployment commands
    ./1-create-bucket.sh
    ./2-build-layer.sh
    ./3-deploy.sh
    ./4-invoke.sh
  6. Deploy an AWS Lambda C# function using Visual Studio

    main

    If you are using Visual Studio, you can manage your Lambda function lifecycle through the AWS Explorer and project context menus:

    • Deploy: Right-click the project in Solution Explorer and select Publish to AWS Lambda.
    • View Function: Double-click the function name beneath the AWS Lambda node in the AWS Explorer tree to open the Function View window.
    • Test: Use the Test Invoke tab within the Function View window to perform testing against your deployed function.
    • Configure Event Sources: Use the Event Sources tab in the Function View window to set up triggers (e.g., Amazon S3 bucket creation).
    • Update Runtime: Use the Configuration tab in the Function View window to modify runtime settings.
    • View Logs: Use the Logs tab in the Function View window to inspect execution logs.
  7. Set up the Blank function (Java) sample application

    main

    To use the Blank function (Java) sample, ensure you meet the following requirements:

    • An AWS account.
    • Java 8 runtime environment (SE JRE).
    • Gradle 5 or Maven 3.
    • Bash shell (default on Linux/macOS; use WSL on Windows).
    • AWS CLI v1.17 or newer.

    Follow these steps to initialize the project:

    1. Clone the repository and navigate to the sample directory:
      git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
      cd aws-lambda-developer-guide/sample-apps/blank-java
    2. Create a new S3 bucket for deployment artifacts by running ./1-create-bucket.sh.
    $ git clone https://github.com/awsdocs/aws-lambda-developer-guide.git
    $ cd aws-lambda-developer-guide/sample-apps/blank-java
    $ ./1-create-bucket.sh
  8. Test and invoke the Blank function (Java)

    main

    Invoke the deployed Lambda function to verify it works by running ./4-invoke.sh. The script will invoke the function multiple times; press CTRL+C to stop the execution.

    To view traces and service maps, use the AWS X-Ray console. To view the application management interface, navigate to the applications page in the AWS Lambda console and select blank-java.

    ./4-invoke.sh