Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update python lambda #537

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions python/n_vault/template.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VAULT_STACK_VERSION = 26
VAULT_STACK_VERSION = 27

TEMPLATE_STRING = f"""
{{
Expand Down Expand Up @@ -311,7 +311,7 @@
}},
"Handler": "index.handler",
"MemorySize": 128,
"Runtime": "python3.10",
"Runtime": "python3.12",
"Timeout": 300,
"Role": {{
"Fn::GetAtt": [
Expand All @@ -327,28 +327,28 @@
"Fn::Join": [
"\\n",
[
"import json",
"import logging",
"import boto3",
"import base64",
"import boto3",
"import cfnresponse",
"import logging",
"log = logging.getLogger()",
"log.setLevel(logging.INFO)",
"kms = boto3.client('kms')",
"SUCCESS = 'SUCCESS'",
"FAILED = 'FAILED'",
"def handler(event, context):",
" ciphertext = event['ResourceProperties']['Ciphertext']",
" responseData = {{}}",
" try:",
" responseData['Plaintext'] = kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext').decode()",
" log.info('Decrypt successful!')",
" cfnresponse.send(event, context, SUCCESS, responseData, event['LogicalResourceId'])",
" except Exception as e:",
" error_msg = 'Failed to decrypt: ' + repr(e)",
" log.error(error_msg)",
" cfnresponse.send(event, context, FAILED, responseData, event['LogicalResourceId'])",
" raise Exception(error_msg)"
" ciphertext = event['ResourceProperties']['Ciphertext']",
" resource_id = event.get('LogicalResourceId')",
" response_data = {{}}",
" try:",
" response_data['Plaintext'] = kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext').decode()",
" log.info('Decrypt successful!')",
" cfnresponse.send(event, context, SUCCESS, response_data, resource_id)",
" except Exception as e:",
" error_msg = 'Failed to decrypt: ' + repr(e)",
" log.error(error_msg)",
" cfnresponse.send(event, context, FAILED, response_data, resource_id)",
" raise Exception(error_msg)"
]
]
}}
Expand Down
32 changes: 16 additions & 16 deletions rust/src/template.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::sync::LazyLock;

/// Cloudformation stack version.
pub const VAULT_STACK_VERSION: u32 = 26;
pub const VAULT_STACK_VERSION: u32 = 27;

/// Return Cloudformation stack template JSON.
/// Workaround for accessing string inside `LazyLock`.
Expand Down Expand Up @@ -321,7 +321,7 @@ static TEMPLATE_STRING: LazyLock<String> = LazyLock::new(|| {
},
"Handler": "index.handler",
"MemorySize": 128,
"Runtime": "python3.10",
"Runtime": "python3.12",
"Timeout": 300,
"Role": {
"Fn::GetAtt": [
Expand All @@ -337,28 +337,28 @@ static TEMPLATE_STRING: LazyLock<String> = LazyLock::new(|| {
"Fn::Join": [
"\n",
[
"import json",
"import logging",
"import boto3",
"import base64",
"import boto3",
"import cfnresponse",
"import logging",
"log = logging.getLogger()",
"log.setLevel(logging.INFO)",
"kms = boto3.client('kms')",
"SUCCESS = 'SUCCESS'",
"FAILED = 'FAILED'",
"def handler(event, context):",
" ciphertext = event['ResourceProperties']['Ciphertext']",
" responseData = {}",
" try:",
" responseData['Plaintext'] = kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext').decode()",
" log.info('Decrypt successful!')",
" cfnresponse.send(event, context, SUCCESS, responseData, event['LogicalResourceId'])",
" except Exception as e:",
" error_msg = 'Failed to decrypt: ' + repr(e)",
" log.error(error_msg)",
" cfnresponse.send(event, context, FAILED, responseData, event['LogicalResourceId'])",
" raise Exception(error_msg)"
" ciphertext = event['ResourceProperties']['Ciphertext']",
" resource_id = event.get('LogicalResourceId')",
" response_data = {}",
" try:",
" response_data['Plaintext'] = kms.decrypt(CiphertextBlob=base64.b64decode(ciphertext)).get('Plaintext').decode()",
" log.info('Decrypt successful!')",
" cfnresponse.send(event, context, SUCCESS, response_data, resource_id)",
" except Exception as e:",
" error_msg = 'Failed to decrypt: ' + repr(e)",
" log.error(error_msg)",
" cfnresponse.send(event, context, FAILED, response_data, resource_id)",
" raise Exception(error_msg)"
]
]
}
Expand Down