Developing an S3 Bucket policy with Pulumi

I am currently working on setting up an S3 bucket and a corresponding S3 policy using Pulumi with TypeScript. However, during the pipeline execution, I encountered the following error in the test stage:

expect(received).toEqual(expected) // deep equality
- Expected  - 2
+ Received  + 2
@@ -8,12 +8,12 @@
          },
        },
        "Effect": "Deny",
        "Principal": "*",
        "Resource": Array [
-         "app-testsupun-buyapp-bucket-arn",
-         "app-testsupun-buyapp-bucket-arn/*",
+         null,
+         "undefined/*",
        ],
      },
    ],
    "Version": "2012-10-17",
  }
  137 |             Statement: [
  138 |               {
> 139 |                 Effect: 'Deny',
      |                                ^
  140 |                 Principal: '*',
  141 |                 Action: 's3:*',
  142 |                 Resource: ['app-testsupun-buyapp-bucket-arn', 'app-testsupun-buyapp-bucket-arn/*'],
  at infra/resource.unit.ts:139:32
  at node_modules/@pulumi/output.ts:440:31
  at node_modules/@pulumi/pulumi/output.js:21:71
  at Object.<anonymous>.__awaiter (node_modules/@pulumi/pulumi/output.js:17:12)
  at applyHelperAsync (node_modules/@pulumi/pulumi/output.js:257:12)
  at node_modules/@pulumi/output.ts:352:13

This indicates that null and undefined values are being received for the Resource argument. Below is the code snippet I used to create the S3 bucket and the S3 policy:

const appS3 = new s3Bucket.S3Resource('app-testsupun-buyapp-bucket', {
bucketArgOpts: {
  args: {
    bucket: 'app-testsupun-buyapp-bucket',
    tags: {
      application: 'app',
    },
  },
},
  });

const appS3Policy = new aws.s3.BucketPolicy(
'default-testsupun-policy',
{
  bucket: appS3.bucket.bucket,
  policy: {
    Version: '2012-10-17',
    Statement: [
      {
        Effect: 'Deny',
        Principal: '*',
        Action: 's3:*',
        Resource: [
          /* pulumi.output(appS3.bucket.bucket).apply(() => `arn:aws:s3:::${bucketname}/*`), */
          appS3.bucket.arn,
          pulumi.interpolate`${appS3.bucket.arn}/*`,
        ],
        Condition: {
          Bool: {
            'aws:SecureTransport': 'false',
          },
        },
      },
    ],
  },
},
{
  dependsOn: [appS3],
},
);

Answer №1

In my opinion, it would be best to update the dependsOn attribute from [appS3] to [appS3.bucket].

It seems that appS3 does not inherit from the Resource class, causing issues with your current dependsOn configuration. This could lead to problems when attempting to apply changes in test mode as Pulimi may struggle to establish dependencies between resources.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps should be taken to rectify the issue of a missing type in a property within an

After spending the last 2 years working on Angular, I am now encountering an issue with a new interface for the first time. The specific error message is as follows: Type 'MatTableDataSource<Tasks[]>' is missing the following properties f ...

Utilizing NPM Workspaces to efficiently distribute TypeScript definition files (`*.d.ts`) across multiple workspaces

In my TypeScript monorepo utilizing NPM Workspaces, I have two packages: A and B. Package B requires type definitions from package A. To accomplish this, I included a reference to A's definition file in the tsconfig.json of package B. However, somet ...

After deploying to the production server, Next.js is failing to fetch images using the image URL

Our production deployment setup includes a network of 3 linux machines, with two dedicated to deployment and one serving as an nginx proxy. For development deployment, we utilize a separate linux machine. Within our frontend (built using the nextjs framew ...

Protect a web address with the power of AngularJS, Firebase, and S3

I am looking to create a website using an AWS S3 bucket for storing videos, along with AngularJS and Firebase for authentication. My main concern is ensuring that the URL to access the video content (/video) is secure and can only be accessed by authentica ...

Unable to break out of loop within TypeScript Protractor code

Currently I am delving into the realm of protractor and typescript while engaged in creating an automation test suite utilizing these technologies. I formulated a method as: private allElements = $$('.some-list li'); public async getDateElem ...

What is the best way to display several components in a particular location within a parent component using react-native?

I am struggling to position multiple components within a parent component at a specific location determined by some calculations. The calculations for the vertical position seem accurate, but the components are not appearing where they should be. I have ex ...

Using navigateByUrl() to pass a query parameter

When I click on an icon, I want to navigate to a new page. Here's the code snippet: this.prj = e.data.project_number; this.router.navigateByUrl('/dashboard/ProjectShipment/634'); Instead of hardcoding the query parameter 000634, I need ...

Issue with TypeScript causing missing data upon user deletion

I am currently using the Chrome browser and working on a project involving a table listing users. I have implemented CRUD functionalities for this table. However, when trying to delete a user, sometimes the data reloads successfully, but other times it doe ...

Creating a function that is accessible to the entire module

Creating a universal function in a file that is not a module: example.ts: function example() {} You can easily call this function from another file, say test.ts, without needing to import the function from example.ts: test.ts: example(); // calling univ ...

Error message stating: rxjs and firebase encountered a TypeError when attempting to add property 0 because the object is not

My angular application interacts with firebase firestore as the backend database. I am working on a function to retrieve document snapshots from firestore in a generic way. Here is the code snippet where I encounter an error: /** * Get a 'liste ...

Problem with Extending Jest Matchers in VS Code TypeScript

I've developed unique Jest matchers to enhance expect for handling AxiosResponse objects. Although I've followed the standard method for expanding Jest's matcher types, my custom matchers are not being recognized by TypeScript. The error di ...

Issues with capturing object values in Typescript with Angular click event

Encountering an issue with binding values when passing Event parameters from the Template to Typescript Button click event. https://i.sstatic.net/SEnL6.png Take a look at the object below, it is properly binding but not reflecting the same in the Type ...

The dynamically loaded JavaScript file was unable to access the constructor, resulting in the error message "X is not a constructor."

Attempting to eliminate the use of import statements and instead dynamically load Javascript files using a specific class. This particular class is used for this purpose: export function JSImport<T>( importPromise: Promise<T>, ): Promise&l ...

Simplify deeply nested JSON structures with TypeScript generics

After receiving the JSON data shown below, I have a specific model in mind for deserialization: {"results": {"data": { "id":"93cba9bd-2969-3214-b26f-7f42d20241a4", "first_name":"PSU", "last_name":"Bot", "profile": { "data":{"abou ...

Typescript - dealing with a null array reference

Currently, I am working on developing an application using typescript/angular. In this project, I have a service that retrieves JSON data and I want to display these downloaded objects. However, there is a possibility that the number of objects retrieved m ...

Assigning string properties to different types

I have numerous data types, each with a common property called dataType, and I am currently mapping each one to that specific value: interface GroupData { dataType: "group"; name: string; people: PersonData[]; } interface PersonData ...

Tips for setting a default value in a generic function in TypeScript, where the default argument's type is determined by the generic parameter

One of my functions calls an API and accepts a parameter to limit the fields returned by the API: type MaximumApiResponse = { fieldA: string, fieldB: number } const f = async <U extends keyof MaximumApiResponse>( entity: number, prop ...

Deduce the property type by the existence of the value

Here's a situation I'm trying to address in a simple way: if the entity prop is present, I want the onClick callback to receive the entity string, otherwise it should receive nothing. type SnakeOrCamelDomains = "light" | "switch" | "input_boolean ...

Encountering TypeScript error while utilizing Vue.mixin in Vue framework

I am currently developing an SSR application using Vue.js. During my development process, I encountered a TypeScript error while attempting to do this. Vue.mixin({ beforeRouteUpdate (to, from, next) { const { asyncData } = this.$options ...

Ways to help a child notice when a parent's variable changes

Looking for help with passing data to a child component? Check out this Plunker: http://plnkr.co/edit/G1EgZ6kQh9rMk3MMtRwA?p=preview @Component({ selector: 'my-app', template: ` <input #x /> <br /> <child [value] ...