

# Getting started with AWS Systems Manager Cloud Extensions

This tutorial shows you how to set up AWS Systems Manager Cloud Extensions and use your first extension. You create a profile, add the Parameter Store extension to the profile, and call the extension from your application code.

**Topics**
+ [Getting started on the console](#cloud-extensions-getting-started-getting-started-on-the-console)
+ [Setting up Cloud Extensions with an AI agent](#cloud-extensions-getting-started-setting-up-cloud-extensions-with-an-ai-agent)
+ [Getting started with the AWS CLI](#cloud-extensions-getting-started-getting-started-with-the-aws-cli)
+ [Next steps](#cloud-extensions-getting-started-next-steps)

## Getting started on the console
<a name="cloud-extensions-getting-started-getting-started-on-the-console"></a>

The **Cloud Extensions** page of the Systems Manager console guides you through three steps. To open the page:

1. Open the Systems Manager console at [https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/).

1. In the navigation pane, choose **Cloud Extensions**.

The **Get started** section of the page shows the following steps:

1. **Create a profile** – A profile stores extensions and their settings so that your resources can share them. Choose **Create profile**.

1. **Add extensions to the profile** – Choose extensions from the catalog, and configure their settings. Choose **Add extension**.

1. **Connect the profile to your resources** – To use your extensions, your resources must point to the profile that you want them to use. To learn how, choose **Learn how to connect your compute resources**.

### Browsing the Extension catalog
<a name="cloud-extensions-getting-started-browsing-the-extension-catalog"></a>

The **Extension catalog** tab lists the extensions that you can add to a profile. Each extension shows its name and a short description.

**To add an extension from the catalog**

1. On the **Extension catalog** tab, find the extension. To search, enter text in the **Find extensions** box. You can switch between a card view and a list view.

1. Select the extension.

1. Choose **Add to profile**. This button isn't available until you select an extension.

To read about an extension before you add it, choose its name. The page of the extension has the **Settings**, **Capabilities**, and **Versions** tabs.

The **Profiles** tab lists your profiles.

### Adding the Parameter Store extension on the console
<a name="cloud-extensions-getting-started-adding-the-parameter-store-extension-on-the-console"></a>

**To add the Parameter Store extension to a profile**

1. On the **Extension catalog** tab, select **AWS Systems Manager Parameter Store**, and then choose **Add to profile**.

1. On the **Choose a profile** page, choose **Existing profile** and then choose the profile in **Profile**, or choose **New profile**. Choose **Next**.

1. On the **Configure extension** page, under **Update method**, choose **Latest (recommended)**.

1. Under **Settings**, keep the default values of **Cache TTL** and **Cache size**, or enter your own values.

1. Review the **Capabilities summary**. The summary lists the **Call Parameter Store** capability. Choose **Next**.

1. On the **Review and add** page, choose **Add to profile**.

**To confirm that the profile contains the extension**

1. On the **Cloud Extensions** page, choose the **Profiles** tab, and then choose the name of the profile.

1. On the **Extensions** tab, find **AWS Systems Manager Parameter Store**. The **Version** and **Update method** columns show the version and the update method.

Resources that use the profile get the change the next time that they start or receive an invocation.

To change the settings, the runtime settings, or the update method on the console, see [Working with profiles on the console](cloud-extensions-profiles.md#cloud-extensions-profiles-working-with-profiles-on-the-console) and [Updating an extension on the console](cloud-extensions-updates.md#cloud-extensions-updates-updating-an-extension-on-the-console).

## Setting up Cloud Extensions with an AI agent
<a name="cloud-extensions-getting-started-setting-up-cloud-extensions-with-an-ai-agent"></a>

The **Or let your agent set it up** section of the **Cloud Extensions** page has two options:
+ **Get setup prompt** – Shows a prompt that you paste into your own AI agent. The prompt has the agent suggest and confirm a profile name, and help you choose extensions. Then, for each function or container that you name, the agent adds the matching Lambda layer or container image and sets `AWS_CLOUDEXTENSIONS_PROFILE`. The prompt tells the agent to ask before it changes anything.
+ **Ask AWS assistant** – Opens the AWS assistant of the console with the same prompt.

## Getting started with the AWS CLI
<a name="cloud-extensions-getting-started-getting-started-with-the-aws-cli"></a>

The rest of this topic shows the same steps with the AWS CLI.

### Prerequisites
<a name="cloud-extensions-getting-started-prerequisites"></a>

Before you begin, verify that:
+ You have an AWS Lambda function or a container environment where you want to use Cloud Extensions.
+ You have AWS credentials configured for the AWS CLI or SDK, with permission to call the Cloud Extensions API.
+ You can create an IAM role in your account.

### Step 1: Installing the Cloud Extensions runtime
<a name="cloud-extensions-getting-started-step-1-installing-the-cloud-extensions-runtime"></a>

Choose the installation method for your environment.

**For AWS Lambda functions:**

Cloud Extensions publishes the ARN of its Lambda layer as a public parameter in AWS Systems Manager Parameter Store. The parameter holds the ARN of the layer in the AWS Region that you query. Get the ARN for your function architecture:

```bash
aws ssm get-parameter \
  --name /aws/service/aws-cloudextensions/lambda-extension/amd64/latest \
  --query 'Parameter.Value' \
  --output text
```

For arm64 functions, use `/aws/service/aws-cloudextensions/lambda-extension/arm64/latest`.

Add the ARN to your Lambda function as a layer. For the console steps, see [Configuring Lambda extensions](https://docs.aws.amazon.com/lambda/latest/dg/extensions-configuration.html) in the *AWS Lambda Developer Guide*. To use the AWS CLI, run the following command:

```bash
aws lambda update-function-configuration \
  --function-name my-function \
  --layers {{layer-arn}}
```

**For containerized applications:**

Pull the Cloud Extensions container image from Amazon ECR:

```bash
docker pull public.ecr.aws/aws-cloudextensions/cloudextensions-runtime:latest
```

The container includes the Cloud Extensions runtime, aws-cloudx-rt.

The runtime retrieves the state of its profile with the credentials that it uses for AWS calls. In Lambda, those credentials belong to the function role. In a container, the credentials depend on how you run the container. Grant the credentials that the runtime uses the `cloudextensions:SyncState` action on all resources. For the policy, see [Permissions for the runtime](cloud-extensions-security.md#cloud-extensions-security-permissions-for-the-runtime).

### Step 2: Creating a profile
<a name="cloud-extensions-getting-started-step-2-creating-a-profile"></a>

To create a profile for this tutorial, run the following command:

```bash
aws cloudextensions create-profile \
  --name my-application \
  --description "Profile for my application"
```

The command returns the profile, including the profile ID, ARN, description, and extension defaults. When you create a profile without specifying authentication, the profile uses runtime credentials. Cloud Extensions doesn't generate a key.

To list all profiles in your account, run the following command:

```bash
aws cloudextensions list-profiles
```

For more information about profiles, see [Working with AWS Systems Manager Cloud Extensions profiles](cloud-extensions-profiles.md).

### Step 3: Choosing an extension
<a name="cloud-extensions-getting-started-step-3-choosing-an-extension"></a>

To list the released extensions, run the following command:

```bash
aws cloudextensions list-extensions
```

The output lists the latest version of each extension, with its ID, name, ARN, version, description, and release notes. For this tutorial, use the Parameter Store extension, `aws:parameterstore`. To see the settings, capabilities, and interfaces that the extension declares, run the following command:

```bash
aws cloudextensions get-extension --identifier aws:parameterstore
```

In the output, review the following fields of the `configuration` object:
+ **settings** – The settings that you can configure, with the type, default value, and constraints of each setting.
+ **capabilities** – The operations that the extension requests permission to perform in your environment. Each capability includes a purpose and a flag that shows whether the extension requires the capability.
+ **interfaces** – The interfaces that the extension serves. Each interface has an ID and a base path.

### Step 4: Creating an IAM execution role
<a name="cloud-extensions-getting-started-step-4-creating-an-iam-execution-role"></a>

An extension assumes an IAM role when it calls AWS services. You create this role. Attach permissions policies to the role that allow the AWS actions that the extension needs to do its work. The capabilities that the extension declares describe those actions. For the Parameter Store extension, the following permissions policy allows read access to the parameters under `/myapp/`:

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ssm:GetParameter",
        "ssm:GetParameters"
      ],
      "Resource": "arn:aws:ssm:us-east-1:111122223333:parameter/myapp/*"
    }
  ]
}
```

The role also needs a trust policy. In the trust policy, allow the role that the runtime runs as to assume the role. For an example, see [IAM execution role](cloud-extensions-security.md#cloud-extensions-security-iam-execution-role).

To use the role for every extension in the profile, set the role as an extension default:

```bash
aws cloudextensions update-profile \
  --identifier my-application \
  --extension-defaults executionRole=arn:aws:iam::111122223333:role/CloudExtensionsExecutionRole
```

### Step 5: Adding the extension to the profile
<a name="cloud-extensions-getting-started-step-5-adding-the-extension-to-the-profile"></a>

To add the extension to the profile, create a profile entry:

```bash
aws cloudextensions create-profile-entry \
  --profile-identifier my-application \
  --extension-identifier aws:parameterstore \
  --version-policy updateStrategy=AUTOMATIC,versionSelector=1.x.x \
  --approve parameterStoreRead
```

This command makes the following choices:
+ The version policy tracks new releases automatically, but only within major version 1.
+ The `--approve` option approves the capability that you reviewed in Step 3. The path of a capability that isn't inside a setting group is the ID of the capability. For this extension, the ID is `parameterStoreRead`. An extension can use a capability only after you approve the capability.

The command returns the profile entry, including the following fields:
+ **effectiveSettings** – The setting values that the extension uses, including default values.
+ **approved** – The capabilities that you approved.
+ **inherited** – The profile defaults that apply to the entry, such as the execution role.

To override a default setting value, add the `--settings` option. For example, `--settings file://settings.json`.

### Step 6: Connecting the profile to your resources
<a name="cloud-extensions-getting-started-step-6-connecting-the-profile-to-your-resources"></a>

For your extensions to work, your resources must point to the profile that you want them to use. A resource is a Lambda function or a container that runs the Cloud Extensions runtime. Many resources can share one profile. Cloud Extensions doesn't record which resources use a profile.
+ **Lambda** – Set the `AWS_CLOUDEXTENSIONS_PROFILE` environment variable of the function to the name or ID of the profile. The following command replaces all environment variables of the function, so include the variables that the function already has:

  ```bash
  aws lambda update-function-configuration \
    --function-name my-function \
    --environment "Variables={AWS_CLOUDEXTENSIONS_PROFILE=my-application}"
  ```
+ **Containers** – Pass the `--profile` option to the runtime. The entrypoint of the image is the runtime, so you add the option to the command of the container. For example, add `--profile my-application`.

Name the profile in each Lambda function and each container that uses it. For more information, see [Connecting profiles to your resources](cloud-extensions-profiles.md#cloud-extensions-profiles-connecting-profiles-to-your-resources).

The IAM execution role from Step 4 and the capabilities that you approve in Step 5 control what the extensions can do.

### Step 7: Securing the runtime endpoint
<a name="cloud-extensions-getting-started-step-7-securing-the-runtime-endpoint"></a>

A new profile uses runtime credentials. Callers sign each request with the AWS credentials that the runtime has. In a Lambda function or a container, those credentials are the ones that the function or the container already has. You don't create or store a key. For this tutorial, you can keep the default. To choose a different option, use one of the following procedures.

On the console, you change the authentication on the **Runtime settings** tab of the profile. For the steps, see [Changing the authentication settings on the console](cloud-extensions-security.md#cloud-extensions-security-changing-the-authentication-settings-on-the-console). The rest of this step shows the AWS CLI.

**Option 1: Use runtime credentials (default, recommended)**

You don't need to run a command. To return a profile to runtime credentials after you use another option, send an empty `authentication` object:

```bash
aws cloudextensions update-profile \
  --identifier my-application \
  --extension-defaults '{
    "interfaceDefaults": { "http": { "authentication": {} } }
  }'
```

**Option 2: Use an extension key with a secret key from AWS Secrets Manager**

Use an extension key only if your callers can't use the credentials of the runtime. First, ask Cloud Extensions to generate the key:

```bash
aws cloudextensions update-profile \
  --identifier my-application \
  --extension-defaults '{
    "interfaceDefaults": {
      "http": {
        "authentication": { "extensionKey": {} }
      }
    }
  }'
```

The response contains the access key ID and the secret key. Cloud Extensions returns the secret key only this once. Store the secret key in Secrets Manager:

```bash
aws secretsmanager create-secret \
  --name cloud-extensions/auth \
  --secret-string "{{secret-key-from-the-response}}"
```

Reference the secret in the authentication setting of the profile:

```bash
aws cloudextensions update-profile \
  --identifier my-application \
  --extension-defaults '{
    "interfaceDefaults": {
      "http": {
        "authentication": {
          "extensionKey": {
            "secretKey": {
              "reference": "arn:aws:secretsmanager:us-east-1:111122223333:secret:cloud-extensions/auth-AbCdEf"
            }
          }
        }
      }
    }
  }'
```

Secrets Manager protects a secret key better than a literal value. For testing only, you can pass the secret key as a literal value:

```json
"secretKey": { "literal": "my-test-secret-key-0123456789" }
```

**Option 3: Turn authentication off**

Turn authentication off only if you trust every process that can reach localhost on your compute. Without authentication, any process that can reach localhost can call your extensions.

```bash
aws cloudextensions update-profile \
  --identifier my-application \
  --extension-defaults '{
    "interfaceDefaults": {
      "http": {
        "authentication": { "none": true }
      }
    }
  }'
```

### Step 8: Verifying that the extension is accessible
<a name="cloud-extensions-getting-started-step-8-verifying-that-the-extension-is-accessible"></a>

The runtime checks for profile changes every 45 seconds. In Lambda, a change applies in the first invocation after the 45 seconds pass, and the runtime serves the extension on `localhost` port 5333. To confirm, check the runtime logs for messages that show that the runtime retrieved the profile and loaded the extension.

If authentication is on, which is the default, sign requests with SigV4. The next step shows how. A request that you don't sign fails.

To test the extension endpoint with `curl`, turn authentication off for the profile first. For the steps, see Option 3 in Step 7. Then run the following command:

```bash
curl "http://localhost:5333/parameterstore/parameter/value?name=/myapp/config/setting"
```

### Step 9: Calling the extension from your application code
<a name="cloud-extensions-getting-started-step-9-calling-the-extension-from-your-application-code"></a>

Call the extension with HTTP requests to the local endpoint of the runtime. The following Python example reads a parameter value from the Parameter Store extension. The example signs the request with SigV4, using the credentials of the Lambda function or the container, which are the runtime credentials. The example uses `botocore` for signing and the Python standard library for the HTTP request:

```python
import urllib.request
import botocore.session
from botocore.auth import SigV4Auth
from botocore.awsrequest import AWSRequest
REGION = "us-east-1"
# Use localhost, not 127.0.0.1. The runtime routes by host name.
URL = "http://localhost:5333/parameterstore/parameter/value?name=/myapp/database/connection-string"
def get_parameter_value():
    # Sign the request with the credentials of the function or the container
    credentials = botocore.session.Session().get_credentials().get_frozen_credentials()
    request = AWSRequest(method="GET", url=URL)
    SigV4Auth(credentials, "ssm", REGION).add_auth(request)
    # Send the signed request to the extension, which serves the value from its cache
    http_request = urllib.request.Request(URL, headers=dict(request.headers), method="GET")
    with urllib.request.urlopen(http_request) as response:
        return response.read().decode("utf-8")
print(get_parameter_value())
```

If you use an extension key, sign with the access key ID and the secret key of the profile instead. Replace the `credentials` line of `get_parameter_value` with `credentials = Credentials("{{access-key-id}}", "{{secret-key}}")`, and import `Credentials` from `botocore.credentials`. If authentication is off, send the request without a signature.

For the routes, the parameters, and the responses of each extension, see the topic for the extension:
+ [Using the AWS AppConfig extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-appconfig-using.md)
+ [Using the Parameter Store extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-parameter-store-using.md)
+ [Using the Secrets Manager extension in AWS Systems Manager Cloud Extensions](cloud-extensions-ext-secrets-manager-using.md)

### Step 10: Monitoring your extension
<a name="cloud-extensions-getting-started-step-10-monitoring-your-extension"></a>

After your next invocation, check the logs of the extension. In Lambda, the logs are in the CloudWatch Logs log group of the function. In a container, the logs go to the output of the container. Each extension also sends its own metrics to Amazon CloudWatch. You query the metrics with PromQL. For the metrics and the steps, see [CloudWatch metrics](cloud-extensions-monitoring.md#cloud-extensions-monitoring-cloudwatch-metrics).

### Cleaning up
<a name="cloud-extensions-getting-started-cleaning-up"></a>

To delete the profile that you created for this tutorial, run the following command:

```bash
aws cloudextensions delete-profile --identifier my-application
```

Deleting a profile also deletes its profile entries.

If you created the secret and the IAM role for this tutorial, delete them when you no longer need them. To stop using Cloud Extensions in your application, see [Stopping the use of Cloud Extensions](cloud-extensions-profiles.md#cloud-extensions-profiles-stopping-the-use-of-cloud-extensions).

## Next steps
<a name="cloud-extensions-getting-started-next-steps"></a>
+ [Working with AWS Systems Manager Cloud Extensions profiles](cloud-extensions-profiles.md)
+ [Managing AWS Systems Manager Cloud Extensions updates](cloud-extensions-updates.md)
+ [Monitoring AWS Systems Manager Cloud Extensions](cloud-extensions-monitoring.md)
+ [Troubleshooting AWS Systems Manager Cloud Extensions](cloud-extensions-troubleshooting.md)