> For the complete documentation index, see [llms.txt](https://docs.arkannis.net/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.arkannis.net/cloud/aws/lambda/create-lambda-function-for-lightsail.md).

# Create Lambda function for Lightsail

1. Add function name
2. Select runtime (in our case python)
3. Create the function
4. Add code to stop/start instance:

#### Code to STOP Lightsail Instance:

```python
# TO STOP
import json
import boto3
def lambda_handler(event, context):
    client = boto3.client('lightsail', region_name='REGION-NAME')
    response = client.stop_instance(
    instanceName='INSTANCE-NAME'
)
    return {
        'statusCode': 200,
        'body': json.dumps('Lambda has stopped instance')
    }
```

#### Code to START Lightsail Instance:

```python
# TO START
import json
import boto3
def lambda_handler(event, context):
    client = boto3.client('lightsail', region_name='REGION-NAME')
    response = client.start_instance(
    instanceName='INSTANCE-NAME'
)
    return {
        'statusCode': 200,
        'body': json.dumps('Lambda has started instance')
    }t
```

5\. Go to Amazone EventBridge --> Events --> Rules --> Create Rule

![](/files/G1oiPo9TnRGXG0SV31wY)

6\. Select Scheduled --> Next

![](/files/UpNhH4oR5a0QXHSyP8i5)

7\. Select CRON pattern --> Use <mark style="color:green;">`5 2 ? * 7 *`</mark> for Every Saturday at 2:05 GMT (Example) --> Next

![](/files/VzoWGcWUe92QCnQZw2OK)

8\. On the Right side: <mark style="color:purple;">Select tragets(s) --> AWS Service --> Lambda function --> Select Lambda Function Name</mark>

![](/files/zYeUIZhbdk4Ag5zJHr0u)

9\. Click Next --> Review --> Next --> Finished

### Resources:

[Time Conversion Romania](https://www.worldtimebuddy.com/gmt-to-romania-bucharest)

[AWS Cron Expressions Documentation](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.arkannis.net/cloud/aws/lambda/create-lambda-function-for-lightsail.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
