sst: MalformedPolicyDocument: Resource must be in ARN format or "".

Getting this error non-deterministically when creating a next.js site in a VPC linked to a postgres database.

It appears to have to do with the AppDefaultRole and the next.js function.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 19 (5 by maintainers)

Most upvoted comments

Fixed in v3.6.6

This bug happens in sst dev. When linking an Aurora cluster to a function/service, the resources field in the IAM policy contains the cluster ARN. In dev mode, the Aurora cluster is not deployed, causing the policy contains placeholder value.

It’s an oversight on my part 🙏

Here’s the commit - https://github.com/sst/sst/commit/af2f402626e0863bf56cb3ed26376cf112a41501

I am also seeing this issue when trying to link an Aurora Serverless V2 database. It may have also broken my sst dev server as the bridge could no longer connect over web sockets, maybe an IAM policy problem (but not sure)

|  Error       Api sst:aws:Function → ApiRole aws:iam:Role
|    sdk-v2/provider2.go:515: sdk.helper_schema: updating IAM Role (aspect-sam-ApiRole-uswest2): adding inline policy (inline): operation error IAM: PutRolePolicy, https response error StatusCo
de: 400, RequestID: 7a220b1f-3747-4837-9636-9bcc710f32dd, MalformedPolicyDocument: Resource placeholder must be in ARN format or "*".: provider=aws@6.66.2
|  Error       Api sst:aws:Function → ApiRole aws:iam:Role
|  updating urn:pulumi:sam::aspect::sst:aws:Function$aws:iam/role:Role::ApiRole: 1 error occurred:
|
|  IAM: PutRolePolicy, https response error StatusCode: 400, RequestID: 7a220b1f-3747-4837-9636-9bcc710f32dd, MalformedPolicyDocument: Resource placeholder must be in ARN format or "
|  ".

I am now getting this error on every deploy. It is becoming a major blocker. Totally breaks the ability to make progress and no way to debug or work around. Worse, it is inconsistent and seems to just pop up randomly.

I have a similar error: MalformedPolicyDocument: Resource placeholder must be in ARN format or "*".. It happens every time, not every other time as mentioned in the original issue.

Here is the full error:

Nextjs sst:aws:Nextjs → NextjsDevServerRole aws:iam:Role
   sdk-v2/provider2.go:515: sdk.helper_schema: creating IAM Role (nextjs-app-driescruyskens-NextjsDevServerRole-euwest3): adding inline policy (inline): operation error IAM: PutRolePolicy
, https response error StatusCode: 400, RequestID: a9c79568-13e0-457b-8259-88f4c983f1fe, MalformedPolicyDocument: Resource placeholder must be in ARN format or "*".: provider=aws@6.66.2

Here is the CloudTrail log. As you can see there is a dangling “placeholder” value that was not replaced with the actual value.

{
    "eventVersion": "1.10",
    "userIdentity": {
        "type": "AssumedRole",
        "principalId": "<>",
        "arn": "<>",
        "accountId": "<>",
        "accessKeyId": "<>",
        "sessionContext": {
            "sessionIssuer": {
                "type": "Role",
                "principalId": "<>",
                "arn": "<>",
                "accountId": "<>",
                "userName": "<>"
            },
            "attributes": {
                "creationDate": "2025-01-14T13:09:25Z",
                "mfaAuthenticated": "false"
            }
        }
    },
    "eventTime": "2025-01-14T13:09:25Z",
    "eventSource": "iam.amazonaws.com",
    "eventName": "PutRolePolicy",
    "awsRegion": "us-east-1",
    "sourceIPAddress": "<>",
    "userAgent": "APN/1.0 Pulumi/1.0 Pulumi/1.0 Pulumi-Aws/0.11+compatible (+https://pulumi.com) aws-sdk-go-v2/1.32.6 ua/2.1 os/macos lang/go#1.23.4 md/GOOS#darwin md/GOARCH#arm64 api/iam#1.38.2",
    "errorCode": "MalformedPolicyDocumentException",
    "errorMessage": "Resource placeholder must be in ARN format or \"*\".",
    "requestParameters": {
        "roleName": "nextjs-app-driescruyskens-NextjsDevServerRole-euwest3",
        "policyName": "inline",
        "policyDocument": "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":\"secretsmanager:GetSecretValue\",\"Effect\":\"Allow\",\"Resource\":\"placeholder\"},{\"Action\":[\"rds-data:RollbackTransaction\",\"rds-data:ExecuteStatement\",\"rds-data:CommitTransaction\",\"rds-data:BeginTransaction\",\"rds-data:BatchExecuteStatement\"],\"Effect\":\"Allow\",\"Resource\":\"placeholder\"}]}"
    },
    "responseElements": null,
    "requestID": "8d54aa20-b442-4fed-8a25-d5e61f86113e",
    "eventID": "d09cf896-45fa-4d0a-8338-445e004edd08",
    "readOnly": false,
    "eventType": "AwsApiCall",
    "managementEvent": true,
    "recipientAccountId": "<>",
    "eventCategory": "Management",
    "tlsDetails": {
        "tlsVersion": "TLSv1.3",
        "cipherSuite": "TLS_AES_128_GCM_SHA256",
        "clientProvidedHostHeader": "iam.amazonaws.com"
    }
}

here is an MRE:

import type {} from "./.sst/platform/config";

const S3_REGION = "eu-west-3";

export default $config({
  app(input) {
    return {
      name: "nextjs-app",
      removal: input?.stage === "production" ? "retain" : "remove",
      home: "aws",
      providers: {
        aws: {
          region: S3_REGION,
          profile: "<>",
        },
      },
    };
  },
  async run() {
    const vpc = new sst.aws.Vpc("VPC");

    const postgres = new sst.aws.Aurora("Postgres", {
      engine: "postgres",
      vpc,
      dev: {
        username: "postgres",
        password: "postgres",
        database: "postgres",
        port: 5432,
        host: "localhost",
      },
    });

    new sst.aws.Nextjs("Nextjs", {
      vpc,
      link: [
        postgres, // <------------- Adding this triggers the error
      ],
    });
  },
});

I get this error even after removing the stage and the .sst folder so it should be reproducable.

Looks like the following permissions are dropped as soon as I link: Allow: appsync:*. Seems related to the PutResoure Policy error.

Flow goes like this:

  1. Add link: [rds] and vpc to my Function
  2. sst dev will fail with operation error IAM: PutRolePolicy
  3. kill sst dev and restart
  4. deployment succeeds now (no PutRolePolicy error) but now the permission is gone