私はAWS request spot fleet
を作成し、ユーザデータとしてjinja
テンプレートを指定してインスタンスに渡すためにしようとしていますし、私はこの文書を、次の午前: http://boto3.readthedocs.io/en/latest/reference/services/ec2.htmlAWS boto3 request_spot_fleetユーザデータとして神社テンプレートを渡す - ユーザーデータの不正BASE64エンコーディング
見て - request_spot_fleet(**kwargs)
:
'UserData': 'string',
UserData (string) -- The user data to make available to the instances. If you are using an AWS SDK or command line tool, Base64-encoding is performed for you, and you can load the text from a file. Otherwise, you must provide Base64-encoded text.
template_file = (current_dir + '/config/user.jinja')
template = templateEnv.get_template(template_file)
template_vars = template_vars = { 'var1' : var1 }
output_template = template.render(template_vars)
self.output_template = base64.b64encode(output_template).decode("ascii")
エラー:私は文字列にUserDataのを変更した場合
self.output_template = output_template
com.amazonaws.services.ec2.model.AmazonEC2Exception:
Invalid BASE64 encoding of user data
(Service: AmazonEC2; Status Code: 400; Error Code: InvalidParameterValue)
すべてがうまく機能::
self.output_template = base64.b64encode(b'test').decode("ascii")
'UserData': self.output_template,
self.output_template = base64.b64encode(output_template).decode("ascii")
File "/usr/lib/python3.5/base64.py", line 59, in b64encode
encoded = binascii.b2a_base64(s)[:-1]
TypeError: a bytes-like object is required, not 'str'
であるように私はjinja
テンプレートを渡す場合助言がありますか?
AWS SDKを使用していて、AWS SDK(Boto3)を使用している場合は、「Base64エンコーディングはあなたのために実行されます」と明記されています。では、なぜbase64でエンコードされた文字列を渡しているのですか?文字列を渡すだけです。 – helloV
私はこの 'self.output_template = output_template'のようにするとjinjaテンプレートを渡すことができませんが、aws console' com.amazonaws.services.ec2.model.AmazonEC2Exceptionでエラーが表示されます:無効なBASE64エンコーディング(サービス:AmazonEC2;ステータスコード:400;エラーコード:InvalidParameterValue) – Berlin