{{- $app := .AppName | kebabcase}}
# Basic Amazon Lambda Function Usage

## Start the XL Platform
{{if eq .GenerateDockerComposeSetup true}}
Follow the instructions in `xebialabs/USAGE-docker-compose.md`.
{{else}}
Make sure your existing XL Platform is up and running and accessible.
{{end}}

## Deploy the blueprint to the XL Platform

To deploy this blueprint to the XebiaLabs DevOps Platform, open up a terminal in the folder where you generated the configuration. Then run:

```plain
xl apply -f xebialabs.yaml
```

## Deploy to AWS

Go to XL Deploy and look for the `{{$app}}` folder under `Applications`.

### Provision the Lambda Function

1. Select `{{$app}}/{{$app}}-basic-lambda/1.0.0`, click on the ellipsis and select 'Deploy'.
    1. Select `Environments/{{$app}}/{{$app}}-basic-lambda` and click 'Continue'.
    2. Verify that there are no error messages, then click 'Deploy'.

## Run the Lambda Function

### Navigate to the Lambda Function

1. Log in to the AWS management console and navigate to the CloudFormation service ((e.g. https://{{.AWSRegion}}.console.aws.amazon.com/cloudformation).
2. Click on the Stack that was just created: `{{$app}}-basic-lambda`.
3. Click on the 'Resources' tab and click the 'Physical ID' link of the `LambdaFunction`.

### Create a test

1. Click on the 'Select a test event' dropdown.
2. Click on 'Configure test events'.
3. Leave the 'Hello World' Event Template.
4. Use `Test01` for the Event name.
5. In the body, paste the following:

    ```json
    {
      "timeOfDay": "morning",
      "name": "XebiaLabs"
    }
    ```

6. Click 'Create'

### Run the test

1. Make sure `Test01` now appears in the dropdown.
2. Click the 'Test' button.
3. Expand 'Details' in the green 'Execution result' box. You should see:

    ```json
    [
      "Good morning, XebiaLabs!"
    ]
    ```

## Undeploy from AWS

Go to XL Deploy and look for the `{{$app}}` folder under `Environments`.

### Deprovision the Lambda Function

1. Select `Environments/{{$app}}/{{$app}}-basic-lambda/{{$app}}-basic-lambda (1.0.0)`, click on the ellipsis and select 'Undeploy'.
    1. Click 'Undeploy' at the top right of the screen.

