Skip to content

Commit

Permalink
Add #* comments back to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Dec 19, 2024
1 parent 0435a50 commit 3dddb77
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 89 deletions.
2 changes: 2 additions & 0 deletions chat/src/secrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def load_secrets():
SecretsPath = os.getenv('SECRETS_PATH')
EnvironmentMap = [
['API_TOKEN_SECRET', 'dcapi', 'api_token_secret'],
['OPENSEARCH_ENDPOINT', 'index', 'endpoint'],
['OPENSEARCH_MODEL_ID', 'index', 'embedding_model'],
['AZURE_OPENAI_API_KEY', 'azure_openai', 'api_key'],
Expand All @@ -14,6 +15,7 @@ def load_secrets():

client = boto3.client("secretsmanager")
response = client.batch_get_secret_value(SecretIdList=[
f'{SecretsPath}/config/dcapi',
f'{SecretsPath}/infrastructure/index',
f'{SecretsPath}/infrastructure/azure_openai'
])
Expand Down
66 changes: 34 additions & 32 deletions chat/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Description: Websocket Chat API for dc-api-v2
Parameters:
ApiTokenSecret:
ApiTokenName:
Type: String
Description: Secret Key for Encrypting JWTs (must match IIIF server)
Description: Name of the jwt that DC API issues
EnvironmentPrefix:
Type: String
Description: Prefix for Index names
Expand Down Expand Up @@ -175,33 +175,35 @@ Resources:
Action: lambda:InvokeFunction
FunctionName: !Ref ChatFunction
Principal: apigateway.amazonaws.com
ChatDependencies:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName:
Fn::Sub: "${AWS::StackName}-dependencies"
Description: Dependencies for streaming chat function
ContentUri: ./dependencies
CompatibleRuntimes:
- python3.10
LicenseInfo: "Apache-2.0"
Metadata:
BuildMethod: python3.10
#* ChatDependencies:
#* Type: AWS::Serverless::LayerVersion
#* Properties:
#* LayerName:
#* Fn::Sub: "${AWS::StackName}-dependencies"
#* Description: Dependencies for streaming chat function
#* ContentUri: ./dependencies
#* CompatibleArchitectures:
#* - x86_64
#* CompatibleRuntimes:
#* - python3.12
#* LicenseInfo: "Apache-2.0"
#* Metadata:
#* BuildMethod: python3.12
ChatFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src
Runtime: python3.10
Runtime: python3.12
Architectures:
- x86_64
Layers:
- !Ref ChatDependencies
#* Layers:
#* - !Ref ChatDependencies
MemorySize: 1024
Handler: handlers/chat.handler
Timeout: 300
Environment:
Variables:
API_TOKEN_SECRET: !Ref ApiTokenSecret
API_TOKEN_NAME: !Ref ApiTokenName
ENV_PREFIX: !Ref EnvironmentPrefix
HONEYBADGER_API_KEY: !Ref HoneybadgerApiKey
HONEYBADGER_ENVIRONMENT: !Ref HoneybadgerEnv
Expand All @@ -228,23 +230,23 @@ Resources:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !Sub "${ChatMetricsLog.Arn}:*"
Metadata:
BuildMethod: nodejs20.x
#* Metadata:
#* BuildMethod: nodejs20.x
ChatSyncFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src
Runtime: python3.10
Runtime: python3.12
Architectures:
- x86_64
Layers:
- !Ref ChatDependencies
#* Layers:
#* - !Ref ChatDependencies
MemorySize: 1024
Handler: handlers/chat_sync.handler
Timeout: 300
Environment:
Variables:
API_TOKEN_SECRET: !Ref ApiTokenSecret
API_TOKEN_NAME: !Ref ApiTokenName
ENV_PREFIX: !Ref EnvironmentPrefix
HONEYBADGER_API_KEY: !Ref HoneybadgerApiKey
HONEYBADGER_ENVIRONMENT: !Ref HoneybadgerEnv
Expand All @@ -261,14 +263,14 @@ Resources:
- 'es:ESHttpGet'
- 'es:ESHttpPost'
Resource: '*'
# - Statement:
# - Effect: Allow
# Action:
# - logs:CreateLogStream
# - logs:PutLogEvents
# Resource: !Sub "${ChatMetricsLog.Arn}:*"
Metadata:
BuildMethod: nodejs20.x
- Statement:
- Effect: Allow
Action:
- logs:CreateLogStream
- logs:PutLogEvents
Resource: !Sub "${ChatMetricsLog.Arn}:*"
#* Metadata:
#* BuildMethod: nodejs20.x
ChatMetricsLog:
Type: AWS::Logs::LogGroup
Properties:
Expand Down
2 changes: 2 additions & 0 deletions node/src/handlers/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const Honeybadger = require("../honeybadger-setup");
const { StatusCodes } = require("http-status-codes");
const { SECRETS_PATH } = process.env;
const SecretPaths = [
`${SECRETS_PATH}/config/dcapi`,
`${SECRETS_PATH}/infrastructure/index`,
`${SECRETS_PATH}/infrastructure/nusso`,
];
Expand Down Expand Up @@ -64,6 +65,7 @@ const _initializeEnvironment = async function () {
endpoint = new URL(endpoint).hostname;
}

putenv("API_TOKEN_SECRET", secrets.dcapi?.api_token_secret);
putenv("OPENSEARCH_ENDPOINT", endpoint);
putenv("OPENSEARCH_MODEL_ID", secrets.index?.embedding_model);
putenv("NUSSO_API_KEY", secrets.nusso?.api_key);
Expand Down
Loading

0 comments on commit 3dddb77

Please sign in to comment.