Create a Valkey serverless cache with a public endpoint
With a public endpoint, you can connect to an ElastiCache Serverless cache directly over the internet without a VPC. Public endpoints are available on ElastiCache Serverless for Valkey 9.0 or later.
Prerequisites
-
An AWS account with permissions to create ElastiCache resources.
-
Either AdministratorAccess, or IAM permissions that include elasticache:CreateServerlessCache.
If you plan to create a custom user group instead of using the default, you also need
elasticache:CreateUser and elasticache:CreateUserGroup.
-
Your IAM identity must have permission to create caches with a public endpoint. This permission can be restricted using the elasticache:ConnectionType condition key. For more information, see Example Policies: Using Conditions for Fine-Grained Parameter Control.
-
The AWS CLI version 2 installed and configured, for the CLI steps.
With ElastiCache, you can use the system-managed IAM user (default.iam-user) and user group (default.iam-user-group) to get started without creating custom users. To use a custom user group, first create a user group where all users use IAM authentication, then create the cache.
- AWS Management Console
-
Open the ElastiCache console at https://console.aws.amazon.com/elasticache/. If prompted, sign in.
Choose Get started to open the Create cache page.
Under Engine, choose Valkey.
Under Deployment option, choose Serverless.
Under Settings, enter a Name for your cache. Optionally, enter a Description.
Under Engine version, keep the default selected or choose 9 or later.
For Connection type, choose Public.
By default, ElastiCache uses recommended settings that work for most workloads. Choose Customize default settings if you need to change the network type, adjust cache usage limits, or select a different user group. The default user group is default.iam-user-group. All users in the group must use IAM authentication.
(Optional) Under Tags, choose Add new tag and add tags to search and filter your caches, or track your AWS costs.
Choose Create. After submission, you are redirected to the Cache details page, where the cache status is shown as Creating.
Wait until the Status on the Cache details page changes from Creating to Available before connecting to the cache. The page refreshes automatically when the cache is ready.
- AWS CLI
-
Run the following command to create a cache with a public endpoint using the system-managed default IAM user group:
aws elasticache create-serverless-cache \
--serverless-cache-name my-public-cache \
--engine valkey \
--major-engine-version 9 \
--connection-type public \
--user-group-id default.iam-user-group
The command returns a response that includes the cache endpoint:
{
"ServerlessCache": {
"ServerlessCacheName": "my-public-cache",
"Status": "creating",
"Engine": "valkey",
"MajorEngineVersion": "9",
"ConnectionType": "public",
"Endpoint": {
"Address": "my-public-cache-x2e9hv.public.serverless.use1.cache.amazonaws.com",
"Port": 6379
},
"UserGroupId": "default.iam-user-group"
}
}
Note the Endpoint.Address value. You use this value to connect to your
cache.
To use a custom user group instead of the default, replace default.iam-user-group with your user group ID. All users in the user group must use IAM authentication.
- AWS SDK
-
The following examples create a cache with a public endpoint.
Python (boto3)
import boto3
client = boto3.client("elasticache", region_name="us-east-1")
response = client.create_serverless_cache(
ServerlessCacheName="my-public-cache",
Engine="valkey",
MajorEngineVersion="9",
ConnectionType="public",
UserGroupId="default.iam-user-group",
)
print(response["ServerlessCache"]["Endpoint"]["Address"])
JavaScript (AWS SDK v3)
import {
ElastiCacheClient,
CreateServerlessCacheCommand
} from "@aws-sdk/client-elasticache";
const client = new ElastiCacheClient({ region: "us-east-1" });
const response = await client.send(new CreateServerlessCacheCommand({
ServerlessCacheName: "my-public-cache",
Engine: "valkey",
MajorEngineVersion: "9",
ConnectionType: "public",
UserGroupId: "default.iam-user-group",
}));
console.log(response.ServerlessCache?.Endpoint?.Address);
Java (AWS SDK v2)
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.elasticache.ElastiCacheClient;
import software.amazon.awssdk.services.elasticache.model.CreateServerlessCacheRequest;
import software.amazon.awssdk.services.elasticache.model.CreateServerlessCacheResponse;
try (ElastiCacheClient client = ElastiCacheClient.builder()
.region(Region.US_EAST_1)
.build()) {
CreateServerlessCacheResponse response = client.createServerlessCache(
CreateServerlessCacheRequest.builder()
.serverlessCacheName("my-public-cache")
.engine("valkey")
.majorEngineVersion("9")
.connectionType("public")
.userGroupId("default.iam-user-group")
.build());
System.out.println(response.serverlessCache().endpoint().address());
}
After your cache is available, see Connect to a cache with a public endpoint.