https://pulumi.com logo
#general
Title
# general
b

blue-jelly-98553

11/06/2022, 9:49 PM
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

little-cartoon-10569

11/06/2022, 10:55 PM
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

blue-jelly-98553

11/06/2022, 11:00 PM
Ah perfect thanks. Managed to do it with open in python
62 Views