📝
Node.js の Lambda 関数から Python の Lambda 関数を作成してみた
前提
- Lambda 実行ロールには AdministratorAccess 権限を付与
手順
ローカル環境で以下の Python コードを作成、zip ファイル化後、S3 バケットにアップロードします。
lambda_function.py
def lambda_handler(event, context):
return {
"statusCode": 200,
"body": "Hello from Python Lambda!"
}

Node.js 22.x のランタイムで Lambda 関数を作成します。
index.js
const { LambdaClient, CreateFunctionCommand } = require('@aws-sdk/client-lambda');
const client = new LambdaClient({ region: 'ap-northeast-1' });
exports.handler = async (event) => {
const functionName = 'MyPythonFunction';
const s3Bucket = 'your-s3-bucket-name';
const s3Key = 'function.zip';
const roleArn = 'your-lambda-role-arn';
const command = new CreateFunctionCommand({
Code: {
S3Bucket: s3Bucket,
S3Key: s3Key
},
FunctionName: functionName,
Handler: 'lambda_function.lambda_handler',
Role: roleArn,
Runtime: 'python3.12',
Description: 'Python Lambda function created from Node.js',
Publish: true,
Timeout: 3,
MemorySize: 128
});
try {
const result = await client.send(command);
console.log('Function created:', result);
return {
statusCode: 200,
body: JSON.stringify({
message: 'Python Lambda created successfully!',
functionArn: result.FunctionArn
})
};
} catch (error) {
console.error('Error creating function:', error);
return {
statusCode: 500,
body: JSON.stringify({
message: 'Failed to create function',
error: error.message
})
};
}
};
上記 Node.js の Lambda 関数をテスト実行後、以下のメッセージが表示されて Python の Lambda 関数が作成されていれば成功です。
{
"statusCode": 200,
"body": "{\"message\":\"Python Lambda created successfully!\",\"functionArn\":\"arn:aws:lambda:ap-northeast-1:012345678901:function:MyPythonFunction\"}"
}

まとめ
今回は Node.js の Lambda 関数から Python の Lambda 関数を作成してみました。
どなたかの参考になれば幸いです。
Discussion