Skip to content

Swift Lambda MVP #7489

Open
Open
@shepazon

Description

@shepazon

Implement the scenario and service action calls to create examples for each SDK.

Service actions

Service actions can either be pulled out as individual functions or can be incorporated into the scenario, but each service action must be included as an excerpt in the SOS output.

  • CreateFunction
  • GetFunction
  • ListFunctions
  • Invoke
  • UpdateFunctionCode
  • UpdateFunctionConfiguration
  • DeleteFunction

Scenario

A scenario runs at a command prompt and prints output to the user on the result of each service action. A scenario can run in one of two ways: straight through, printing out progress as it goes, or as an interactive question/answer script.

Getting started with functions

Use an SDK to manage Lambda functions: create a function, invoke it, update its code, invoke it again, view its output and logs, and delete it.

This scenario uses two lambda handlers:

^ Note: Handlers don't use AWS SDK API calls

The increment handler is very simple:

  1. It accepts a number, increments it, and returns the new value.
  2. It performs simple logging of the result.

The arithmetic handler is more complex:

  1. It accepts a set of actions ['plus', 'minus', 'times', 'divided-by'] and two numbers, and returns the result of the calculation.
  2. It uses an environment variable to control log level (such as DEBUG, INFO, WARNING, ERROR).
  3. It logs a few things at different levels, such as:
    DEBUG: full event data
    INFO: the result of the calculation
    WARNING: when a divide by zero error occurs

The steps of the scenario are:

Create an IAM role that:
Has an assume_role policy that grants 'lambda.amazonaws.com' the 'sts:AssumeRole' action.
Attaches the 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole' managed role.
You must wait for ~10 seconds after the role is created before you can use it!!!
Create a function (CreateFunction) for the increment handler by packaging it as a zip and either:
Adding it with CreateFunction Code.ZipFile.
--or--
Uploading it to S3 and adding it with CreateFunction Code.S3Bucket/S3Key.
Note: Zipping the file does not have to be done in code.
If you have a waiter, use it to wait until the function is active. Otherwise, call GetFunction until State is Active.
Invoke the function with a number and print the result.
Update the function (UpdateFunctionCode) to the arithmetic handler by packaging it as a zip and either:
Adding it with UpdateFunctionCode ZipFile
--or--
Uploading it to S3 and adding it with UpdateFunctionCode S3Bucket/S3Key.
Call GetFunction until Configuration.LastUpdateStatus is 'Successful' (or 'Failed').
Update the environment variable by calling UpdateFunctionConfiguration and pass it a log level, such as:
Environment={'Variables': {'LOG_LEVEL': 'DEBUG'}}
Invoke the function with an action from the list and a couple of values. Include LogType='Tail' to get logs in the result. Print the result of the calculation and the log.
[Optional] Invoke the function to provoke a divide-by-zero error and show the log result.
List all functions for the account, using pagination (ListFunctions).
Delete the function (DeleteFunction).
Delete the role.

Metadata

Metadata

Assignees

Labels

SwiftThis issue relates to the AWS SDK for Swift

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions