What is the correct way to use `pulumi.FileAsset`?...
# general
b
What is the correct way to use
pulumi.FileAsset
? Wanted to define an AWS policy in a
policy.json
and then reference that file the code below, but pulumi preview is throwing this error when trying that method
error: expected string or JSON map; got *resource.Asset
Copy code
# Create a policy that allows the Lambda role to write to CloudWatch Logs
cloudwatch_policy = aws.iam.RolePolicy(
    resource_name='pulumi-lambda-test-policy',
    role=lambda_role.id,
    policy=pulumi.FileAsset('./policies/cloudwatch_policy.json')
)
I guess I should have asked if that was even possible. Every doc example I've seen has defined the policy json inline.
l
You would need to read the json file. There isn't a Pulumi tool for reading from files and outputting a string: use another library for that.
You need your language's equivalent of
fs.readFileSync()
.
b
Ah perfect thanks. Managed to do it with open in python