Skip to content

Commit

Permalink
Update python lambda (#537)
Browse files Browse the repository at this point in the history
* use python 3.12 runtime

* update python code

* bump template version
  • Loading branch information
Esgrove authored Oct 17, 2024
1 parent 548ee98 commit 11bac01
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
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

0 comments on commit 11bac01

Please sign in to comment.