Skip to content

Commit cc9378f

Browse files
authored
chore: more examples and readme updates (#517)
1 parent e142ad5 commit cc9378f

9 files changed

Lines changed: 42 additions & 20 deletions

File tree

CONTRIBUTING.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,18 @@ poetry run isort .
169169

170170
## Tests :zap:
171171

172-
Integration tests require an api key for testing. Set the env vars `MOMENTO_API_KEY` and `MOMENTO_ENDPOINT` to
173-
provide it. The env `TEST_CACHE_NAME` is also required, but for now any string value works.
172+
Integration tests require the env vars `MOMENTO_API_KEY`, `MOMENTO_ENDPOINT`, and `V1_API_KEY`.
173+
The env var `TEST_CACHE_NAME` is also required, but for now any string value works.
174174

175175
Example of running tests against all python versions:
176176

177177
```
178-
MOMENTO_API_KEY=<api key> MOMENTO_ENDPOINT=<endpoint> TEST_CACHE_NAME=<cache name> poetry run pytest
178+
MOMENTO_API_KEY=<v2 api key>
179+
MOMENTO_ENDPOINT=<endpoint>
180+
V1_API_KEY=<v1 api key>
181+
TEST_CACHE_NAME=<cache name>
182+
183+
poetry run pytest
179184
```
180185

181186
### For M1 Users
@@ -188,7 +193,7 @@ a github issue with us to let us know. And in the meantime you can work around
188193
issue by installing Rosetta 2 and re-running with:
189194

190195
```
191-
arch -x86_64 MOMENTO_API_KEY=<api key> MOMENTO_ENDPOINT=<endpoint> TEST_CACHE_NAME=<cache name> poetry run pytest
196+
arch -x86_64 MOMENTO_API_KEY=<v2 api key> MOMENTO_ENDPOINT=<endpoint> V1_API_KEY=<v1 api key> TEST_CACHE_NAME=<cache name> poetry run pytest
192197
```
193198

194199
### Developing new test cases?

README.template.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44

55
The Momento Python SDK package is available on pypi: [momento](https://pypi.org/project/momento/).
66

7-
## Usage
7+
## Prerequisites
8+
9+
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com/api-keys)
10+
- A Momento service endpoint is required. You can find a [list of them here](https://docs.momentohq.com/platform/regions)
811

9-
The examples below require an environment variable named `MOMENTO_API_KEY` which must
10-
be set to a valid Momento API key. You can get one from the [Momento Console](https://console.gomomento.com).
12+
## Usage
1113

1214
Python 3.10 introduced the `match` statement, which allows for [structural pattern matching on objects](https://peps.python.org/pep-0636/#adding-a-ui-matching-objects).
1315
If you are running python 3.10 or greater, here is a quickstart you can use in your own project:
@@ -32,8 +34,8 @@ Documentation is available on the [Momento Docs website](https://docs.momentohq.
3234
Working example projects, with all required build configuration files, are available for both Python 3.10 and up
3335
and Python versions before 3.10:
3436

35-
* [Python 3.10+ examples](./examples/py310)
36-
* [Pre-3.10 Python examples](./examples/prepy310)
37+
- [Python 3.10+ examples](./examples/py310)
38+
- [Pre-3.10 Python examples](./examples/prepy310)
3739

3840
## Developing
3941

examples/lambda/README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ The primary use is to provide a base for testing Momento in an AWS lambda enviro
1717
## Prerequisites
1818

1919
- Node version 14 or higher is required (for deploying the Cloudformation stack containing the Lambda)
20-
- To get started with Momento you will need a Momento Auth Token. You can get one from the [Momento Console](https://console.gomomento.com). Check out the [getting started](https://docs.momentohq.com/getting-started) guide for more information on obtaining an auth token.
20+
- A Momento API key is required, you can generate one using the [Momento Console](https://console.gomomento.com/api-keys)
21+
- A Momento service endpoint is required. You can find a [list of them here](https://docs.momentohq.com/platform/regions)
2122

2223
## Deploying the Momento Python Lambda with Docker and AWS CDK
2324

@@ -31,12 +32,11 @@ npm install
3132

3233
To deploy the CDK app you will need to have [configured your AWS credentials](https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-authentication.html#cli-chap-authentication-precedence).
3334

34-
You will also need a superuser token generated from the [Momento Console](https://console.gomomento.com).
35-
3635
Then run:
3736

3837
```
39-
export MOMENTO_API_KEY=<YOUR_MOMENTO_API_KEY>
38+
export MOMENTO_API_KEY=<your-api-key>
39+
export MOMENTO_ENDPOINT=<your-endpoint>
4040
npm run cdk deploy
4141
```
4242

@@ -63,4 +63,5 @@ Follow these steps to create the zip and deploy it to AWS Lambda using the AWS M
6363
8. Under "Runtime settings", set the Handler to index.handler.
6464
9. Switch to the "Configuration" tab.
6565
10. Set the environment variable `MOMENTO_API_KEY` to your API key.
66-
11. Finally, go to the "Test" tab to test your Lambda function.
66+
11. Set the environment variable `MOMENTO_ENDPOINT` to your chosen endpoint.
67+
12. Finally, go to the "Test" tab to test your Lambda function.

examples/lambda/docker/lambda/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def handler(event, lambda_context):
88
cache_name = "default-cache"
99
with CacheClient.create(
1010
configuration=Configurations.Lambda.latest(),
11-
credential_provider=CredentialProvider.from_environment_variable("MOMENTO_API_KEY"),
11+
credential_provider=CredentialProvider.from_environment_variables_v2(),
1212
default_ttl=timedelta(seconds=60),
1313
) as cache_client:
1414
create_cache_response = cache_client.create_cache(cache_name)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
momento==1.8.0
1+
momento==1.28.0

examples/lambda/infrastructure/lib/stack.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as path from 'path';
22
import * as cdk from 'aws-cdk-lib';
3-
import {Construct} from 'constructs';
3+
import { Construct } from 'constructs';
44
import * as lambda from 'aws-cdk-lib/aws-lambda';
55

66
export class MomentoLambdaStack extends cdk.Stack {
@@ -10,13 +10,17 @@ export class MomentoLambdaStack extends cdk.Stack {
1010
if (!process.env.MOMENTO_API_KEY) {
1111
throw new Error('The environment variable MOMENTO_API_KEY must be set.');
1212
}
13+
if (!process.env.MOMENTO_ENDPOINT) {
14+
throw new Error('The environment variable MOMENTO_ENDPOINT must be set.');
15+
}
1316

1417
// Create Lambda function from Docker Image
1518
const dockerLambda = new lambda.DockerImageFunction(this, 'MomentoDockerLambda', {
1619
functionName: 'MomentoDockerLambda',
1720
code: lambda.DockerImageCode.fromImageAsset(path.join(__dirname, '../../docker')), // Point to the root since Dockerfile should be there
1821
environment: {
19-
MOMENTO_API_KEY: process.env.MOMENTO_API_KEY || ''
22+
MOMENTO_API_KEY: process.env.MOMENTO_API_KEY || '',
23+
MOMENTO_ENDPOINT: process.env.MOMENTO_ENDPOINT || ''
2024
},
2125
memorySize: 128,
2226
timeout: cdk.Duration.seconds(30)

examples/lambda/zip/index.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def handler(event, lambda_context):
88
cache_name = "default-cache"
99
with CacheClient.create(
1010
configuration=Configurations.Lambda.latest(),
11-
credential_provider=CredentialProvider.from_environment_variable("MOMENTO_API_KEY"),
11+
credential_provider=CredentialProvider.from_environment_variables_v2(),
1212
default_ttl=timedelta(seconds=60),
1313
) as cache_client:
1414
create_cache_response = cache_client.create_cache(cache_name)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
momento==1.20.1
1+
momento==1.28.0

examples/py310/doc-examples-python-apis.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ def example_API_CredentialProviderFromEnvVar():
4444

4545

4646
def example_API_CredentialProviderFromEnvVarV2():
47+
CredentialProvider.from_environment_variables_v2(
48+
api_key_env_var="MOMENTO_API_KEY", endpoint_env_var="MOMENTO_ENDPOINT"
49+
)
50+
51+
52+
# end example
53+
54+
55+
def example_API_CredentialProviderFromEnvVarV2Default():
4756
CredentialProvider.from_environment_variables_v2()
4857

4958

@@ -233,6 +242,7 @@ async def example_API_GenerateDisposableToken(auth_client: AuthClientAsync):
233242
async def main():
234243
example_API_CredentialProviderFromEnvVar()
235244
example_API_CredentialProviderFromEnvVarV2()
245+
example_API_CredentialProviderFromEnvVarV2Default()
236246
example_API_CredentialProviderFromApiKeyV2()
237247
example_API_CredentialProviderFromDisposableToken()
238248

0 commit comments

Comments
 (0)