<p>I created CodePipeline definition on aws. On the beginning I build docker image and send it to ecr (container registry on aws). When the docker image has been sent to the registry I call lambda function that should update definition of existing deployment by replacing docker image id in that deployment definition. Lambda function is implemented using nodejs, takes recently sent image id and is trying to patch deployment definition. When it's trying to patch the deployment I receive a response like below.</p>

<pre><code>body: {
kind: 'Status',
apiVersion: 'v1',
metadata: {},
status: 'Failure',
message: 'deployments.apps "arch-app" is forbidden: 
          User "system:serviceaccount:arch-user:default" cannot patch resource "deployments" 
          in API group "apps" in the namespace "arch-ns"',
reason: 'Forbidden',
details: [Object],
code: 403
}
</code></pre>

<p>This user account belongs to aws iam and I used it to create test cluster with kubernetes so it's owner of the cluster. Any operation on the cluster I do I do it using this account and it works fine (I can create resources and apply changes on them without any problems using this account).</p>

<p>I created additional role in this namespace and role binding for the aws user account I use but it didn't resolve the issue (and probably was redundant). Lambda function has full permissions to all resources on ecr and eks.</p>

<p><strong>Does/did anybody have similar issue with such deployment patching on eks using lambda function?</strong></p>

Aleksander Stankiewicz
<p>You can check if the service account has RBAC to patch deployment in namespace <code>arch-ns</code></p>

<pre><code>kubectl auth can-i patch deployment --as=system:serviceaccount:arch-user:default -n arch-ns
</code></pre>

<p>If the above command returns <code>no</code> then add necessary role and rolebinding to the service account.</p>

<p>One thing to notice here is that its a <code>default</code> service account in <code>arch-user</code> namespace but trying to perform operation in a different namespace <code>arch-ns</code></p>
