我试图在 AWS Cloudformation YAML 文件中实现类似于下面的内容:
AWSTemplateFormatVersion: 2010-09-09
testAttribute = "test"
Resources:
Lambda:
Type: AWS::Lambda::Function
Properties:
Runtime: python3.7
Role: !GetAtt iam.Arn
MemorySize: 128
Timeout: 10
Handler: lambda_function.lambda_handler
FunctionName: "testName"+${testAttribute}
Description: 'This is my lambda'
Code:
S3Bucket: myBucket
S3Key: "lambda/testName"+${testAttribute}+".zip"
Run Code Online (Sandbox Code Playgroud)
我知道上面不太正确,但在搜索如何实现它时找不到好的答案。有人对这个问题有一些指导吗?
我需要pickle一个字典,然后在通过API调用传输数据之前对其进行Base64编码。
接收器应该解码 Base64 数据,并且 pickle 将其加载回正确的字典中。
问题是它在解码时失败,解码 Base64 数据后它似乎不是相同的二进制数据,因此 Pickle 失败。
我缺少什么?
import pickle
import base64
import json
def publishData():
testDict = {}
testDict['testKey1'] = [1,2,3]
testDict['testKey2'] = [4,5,6]
#Dump the dict to pickle file
with open("test.pkl","wb") as f:
pickle.dump(testDict, f)
#Read the pickle
with open("test.pkl", "rb") as openfile:
data = openfile.read() #Read the raw pickle (binary)
print("publishData - Pickle read : {}".format(data))
#Base64 encode it to ensure formatting in JSON
data = base64.b64encode(data)
print("publishData - Base64 encoded : {}".format(data)) …Run Code Online (Sandbox Code Playgroud) 我使用 jquery 读取文件 (output.txt)。它包含在下面,我将它拆分为一个数组。
名称1.jpg,名称2.jpg,名称3.jpg,名称4.jpg
我可以输出数组的长度并从数组中输出图像,但我很难使输出动态化。
我想实现的场景:
如果fileReadingLength = 10,则显示10张图片(img1,img2,..,img10)。
如果 fileReadingLength = 1,则显示 1 个图像 (img1)。
最好的方法是什么?
<html>
<head>
<script>
var fileReading = new Array();
$.get('output.txt', function(data){
fileReading = data.split(',');
});
$(document).ready(function () {
$("#img1").attr({ "src": fileReading[0] });
$("#img2").attr({ "src": fileReading[1] });
$("fileReadingLength").text(fileReading.length);
});
</script>
</head>
<body>
Number of images: <fileReadingLength></fileReadingLength> <br>
<!-- SHOULD BE CHANGED TO DYNAMIC OUTPUT -->
<img id="img1" src="img1.jpg">
<img id="img2" src="img2.jpg">
</body>
</html>
Run Code Online (Sandbox Code Playgroud)